(setf (mem-aref ptr type &optional (index 0)) new-value)
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)
For compatibility with older versions of CFFI, mem-aref will
produce a pointer for the deprecated bare structure specification, but
it is consistent with other types for the current specification form
) and provides a Lisp object
translated from the structure (by default a plist). In order to obtain
the pointer, you should use the new function mem-aptr.