[gambit-list] interfacing u16vector from the inside of a c-lambda

Christopher Dutchyn cjd032 at cs.usask.ca
Sat Sep 24 21:44:18 EDT 2011


Here is a simple piece of code to do it:

;; double each element of v (with length n) in place
(define double!
  (c-lambda (scheme-object int) ; the vector and it's length
            void
            "//extract array from scheme object
             ___U16* v = ___CAST(___U16*, ___BODY_AS(___arg1, ___tSUBTYPED));
             // perform the C operations
             int i;
             for (i=0; i<___arg2; i+=1) {
               v[i] += v[i];
             }"))

(define *v* (u16vector 0 1 2 3 4 5))

(display *v*)
(newline)
(double! *v* (u16vector-length *v*))
(display *v*)

For more details, the Gambit site, specifically
	http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Using_Gambit_with_External_Libraries#Accessing_Scheme_vectors_within_a_C_function
has many details.

Chris D.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20110925/3b554d16/attachment.htm>


More information about the Gambit-list mailing list