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
double-float
,
single-float
,
(unsigned-byte 32)
,
(signed-byte 32)
,
(unsigned-byte 16)
,
(signed-byte 16)
,
(unsigned-byte 8)
or
(signed-byte 8)
.
array is a foreign pointer to an 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
(mod (* 2 1024 1024))
, but if it 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.
Note: Efficient access to a Lisp vector object is also available. See
sys:typed-aref
in the
LispWorks Reference Manual
.