The FLI :foreign-array
converts between FLI arrays and the foreign array type. It creates an array with the dimensions specified in dimensions, of elements of the type specified by type.
The :foreign-array
type is an aggregate type. In particular, :foreign-array
with more than one dimension is an array containing embedded arrays, not an array of pointers.
Only use the :foreign-array
type when the corresponding foreign code uses an array with a constant declared size. If you need a dynamically sized array, then use a pointer type, allocate the array using the nelems argument to allocate-foreign-object or with-dynamic-foreign-objects and use dereference to access the elements. The pointer type is more efficient than making :foreign-array
types dynamically with different dimensions because the FLI caches information about every different FLI type descriptor that is used.
The following code defines a 3 by 4 foreign array with elements of type :byte
.
(setq farray (fli:allocate-foreign-object
:type '(:foreign-array :byte (3 4))))
The type of this is equivalent to the C declaration
signed char array2[3][4];
LispWorks Foreign Language Interface User Guide and Reference Manual - 29 Sep 2017