Instead through iteration like for or do which assign values to element of
array, deliver list or vector directly to the ctype function imported by ffi.
Because I think that operating the list or vector with built-in functions is
more conveniently than the ctype array.
In the reference, I find _array/list and _array/vector function, here is the
description:
"Like _array, but the Racket representation is a list (or list of lists for a
multidimensional array) of elements copied to and from an underlying C array."
and I test the two functions, after deliver their cpointers as arguments to
ctype function, the list or vector doesn't change. here is my code:
#lang racket
(require ffi/unsafe
ffi/unsafe/define)
(define-ffi-definer define-sm (ffi-lib "scalam"))
;;----------------------------------------------
; sm add element of array with 1.
;
; int sm(int m, int n, double * p)
; {
; int i, j;
; double *p_end;
; p_end = p + (m * n) - 1;
; for (;p <= p_end; p++)
; (*p) = (* p) + 1;
;
; return 0;
; }
;---------------------------------------------------------
(define-sm sm (_fun _int _int _pointer -> _int))
(define t (_array/vector _double 3))
(define x (malloc t))
(define a (ptr-ref x t 0))
(for ((i '(0 1 2)))
(vector-set! a i (+ i 1.0)))
(define info (sm 3 1 x))
(for ((i '(0 1 2)))
(display (vector-ref a i))
;=====================
a doesn't change. or is there something wrong?
thank you.
------------------
lhk____________________
Racket Users list:
http://lists.racket-lang.org/users