Makes a temporary copy of a pointer, executes a list of forms which may use and alter the copy of the pointer across the scope of the macro, and then deallocates the memory provided for the copy of the pointer.
A temporary name used to access a copy of pointer .
The type of the object pointed to by the temporary pointer. This keyword can be used to access the data at the pointer as a different type.
The pointer-type of the temporary pointer.
A FLI pointer of which a copy is made. The lifetime of the copy is across the scope of the
with-coerced-pointer
macro.
A list of forms to be executed across the scope of the temporary pointer binding.
The macro
with-coerced-pointer
makes a temporary copy of a pointer, and executes a list of forms which may use the copy across the scope of the macro. Once the macro has terminated the memory allocated to the copy of the pointer is automatically freed.
In the following example an array of ten integers is defined, pointed to by
array-obj
. The macro
with-coerced-pointer
is used to return the values stored in the array, without altering
array-obj
, or permanently tying up memory for a second pointer.
(setf array-obj
(fli:allocate-foreign-object :type :int
:nelems 10
:initial-contents
'(0 1 2 3 4 5 6 7 8 9)))
(fli:with-coerced-pointer (temp) array-obj
(dotimes (x 10)
(print (fli:dereference temp))
(fli:incf-pointer temp)))