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 object; a pointer to a
char
, whereas
point3
contains a copy of the foreign pointer object.