All Manuals > LispWorks Foreign Language Interface User Guide and Reference Manual > 7 Function, Macro and Variable Reference

NextPrevUpTopContentsIndex

foreign-typed-aref

Accessor
Summary

Accesses a foreign array and can be compiled to efficient code.

Package

fli

Signature

foreign-typed-aref type array index => value

setf (foreign-typed-aref type array index) value => value

Arguments

type

A type specifier.

array

A foreign pointer.

index

A non-negative integer.

Values

value

An element of array.

Description

The accessor 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.

Notes

Efficient access to a Lisp vector object is also available. See sys:typed-aref in the LispWorks User Guide and Reference Manual .

See also

FLI Types
foreign-aref


LispWorks Foreign Language Interface User Guide and Reference Manual - 29 Sep 2017

NextPrevUpTopContentsIndex