All Manuals > Foreign Language Interface User Guide and Reference Manual > 7 Function, Macro and Variable Reference

copy-pointer Function

Summary

Returns a copy of a pointer object.

Package

fli

Signature

copy-pointer pointer &key type pointer-type => copy

Arguments
pointer
A pointer to copy.
type
A FLI type descriptor.
pointer-type
A FLI pointer type descriptor.
Values
copy
A copy of pointer.
Description

The function copy-pointer returns a copy of pointer.

If type is supplied, then it is used as the FLI type that copy points to. Alternatively, if pointer-type is supplied, then it must be a FLI pointer type and it is used as the pointer type of copy. If neither type nor pointer-type are supplied then the type of copy is the same as pointer. An error is signalled if both type and pointer-type are supplied.

Examples

In the following example a pointer point1 is created, pointing to a :char type. The variable point2 is set equal to point1 using setq, whereas point3 is set using copy-pointer. When point1 is changed using incf-pointer, point2 changes as well, but point3 remains the same.

(setq point1 (fli:allocate-foreign-object
              :type :char))
(setq point2 point1)
(setq point3 (fli:copy-pointer point1))
(fli:incf-pointer point1)

The results of this can be seen by evaluating point1, point2, and point3.

The reason for this behavior is that point1 and point2 are Lisp variables containing the same foreign pointer object, a pointer to a char, whereas point3 contains a copy of the foreign pointer object.

See also

make-pointer
with-coerced-pointer
3.1.2 Copying pointers


Foreign Language Interface User Guide and Reference Manual - 01 Dec 2021 19:34:58