Package: cffi

Function mem-aref

Lambda List

mem-aref (ptr type &optional index)

Arguments

ptr -- A foreign pointer.
type -- A foreign type.
index -- An integer. The default is 0.

Details

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)))

Examples

  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)