[gambit-list] FFI numeric vector lengths
Lassi Kortela
lassi at lassi.io
Sun Aug 9 10:09:01 EDT 2020
What causes the following?
;;; Code:
(define (disp . xs) (for-each display xs) (newline))
(define-syntax show
(syntax-rules ()
((_ x) (begin (write 'x) (display " => ") (write x) (newline)))))
(define try-as-u8
(c-lambda (scheme-object) size_t
"___return(___U8VECTORLENGTH(___arg1));"))
(define try-as-u16
(c-lambda (scheme-object) size_t
"___return(___U16VECTORLENGTH(___arg1));"))
(define try-as-u32
(c-lambda (scheme-object) size_t
"___return(___U32VECTORLENGTH(___arg1));"))
(define try-as-u64
(c-lambda (scheme-object) size_t
"___return(___U64VECTORLENGTH(___arg1));"))
(define n 1024)
(disp "u8vector of " n " elements")
(let ((v (make-u8vector n)))
(show (try-as-u8 v))
(show (try-as-u16 v))
(show (try-as-u32 v))
(show (try-as-u64 v)))
(newline)
(disp "u16vector of " n " elements")
(let ((v (make-u16vector n)))
(show (try-as-u8 v))
(show (try-as-u16 v))
(show (try-as-u32 v))
(show (try-as-u64 v)))
(newline)
(disp "u32vector of " n " elements")
(let ((v (make-u32vector n)))
(show (try-as-u8 v))
(show (try-as-u16 v))
(show (try-as-u32 v))
(show (try-as-u64 v)))
;;; Output:
u8vector of 1024 elements
(try-as-u8 v) => 4096
(try-as-u16 v) => 2048
(try-as-u32 v) => 1024
(try-as-u64 v) => 512
u16vector of 1024 elements
(try-as-u8 v) => 8192
(try-as-u16 v) => 4096
(try-as-u32 v) => 2048
(try-as-u64 v) => 1024
u32vector of 1024 elements
(try-as-u8 v) => 16384
(try-as-u16 v) => 8192
(try-as-u32 v) => 4096
(try-as-u64 v) => 2048
More information about the Gambit-list
mailing list