The functions allocate-dynamic-foreign-object, allocate-foreign-object, alloca, and malloc can take the keyword arguments
:type
and
:pointer-type
. It is important to understand the difference between these two arguments.
The
:type
argument is used to specify the name of the FLI type to allocate. Once such an object has been allocated a foreign pointer of type
(:pointer
type
)
is returned, which points to the allocated type. Without this pointer it would not be possible to refer to the object.
The
:pointer-type
argument is used to specify a FLI pointer type. If it is used then the value
pointer-type
should be of the form
(:pointer
type
) or be defined as a FLI pointer type. The function then allocates an object of type
type
, and a pointer to the object of type
type
is returned.
In this first example you can see how to allocate an integer in C, and in LispWorks using the
:type
and the
:pointer-type
arguments.
C > (int *)malloc(sizeof(int))
FLI > (fli:allocate-foreign-object :type :int)
=> #<Pointer to type :INT = #x007E1A60>
FLI > (fli:allocate-foreign-object
:pointer-type '(:pointer :int))
=> #<Pointer to type :INT = #x007E1A60>