The function foreign-typed-aref
accesses a foreign array and is compiled to efficient code when compiled at safety 0. It corresponds to sys:typed-aref
which accesses Lisp vectors.
type must evaluate to a supported element type for foreign arrays. In 32-bit LispWorks these types are double-float
, single-float
, (unsigned-byte 32)
, (signed-byte 32)
, (unsigned-byte 16)
, (signed-byte 16)
, (unsigned-byte 8)
, (signed-byte 8)
and sys:int32
. In 64-bit LispWorks type can also be (unsigned-byte 64)
, (signed-byte 64)
and sys:int64
.
array is a foreign pointer to a FLI array. Memory can be allocated with:
(fli:allocate-foreign-object
:type :double
:nelems
(ceiling byte-size
(fli:size-of :double)))
to get sufficient alignment for any call to foreign-typed-aref
.
In the case the memory is allocated by the operating system the best approach is to reference it from Lisp by a pointer type, to avoid making a :c-array foreign type dynamically.
index should be a valid byte index for array. If index is declared to be of type fixnum
then the compiler will optimize it slightly better. Some parts of the FLI (for example, allocate-foreign-object) assume fixnum
sizes so it is best to use fixnums only.
Efficient access to a Lisp vector object is also available. See sys:typed-aref
in the
LispWorks User Guide and Reference Manual
.
LispWorks Foreign Language Interface User Guide and Reference Manual - 16 Feb 2015