Next: mem-ref, Previous: make-pointer, Up: Pointers
(setf (mem-aref ptr type &optional (index 0)) new-value)
The mem-aref
function is similar to mem-ref
but will
automatically calculate the offset from an index.
(mem-aref ptr type n) ;; is identical to: (mem-ref ptr type (* n (foreign-type-size type)))
CFFI> (with-foreign-string (str "Hello, foreign world!") (mem-aref str :char 6)) => 32 CFFI> (code-char *) => #\Space CFFI> (with-foreign-object (array :int 10) (loop for i below 10 do (setf (mem-aref array :int i) (random 100))) (loop for i below 10 collect (mem-aref array :int i))) => (22 7 22 52 69 1 46 93 90 65)