Copy between a Java array of primitive type and a buffer specified by a foreign pointer.
lw-ji
get-primitive-array-region array &key start end buffer buffer-size => target-buffer, foreign-type
set-primitive-array-region array buffer &key start end => t, foreign-type
array⇩ |
A Java array of primitive type. |
Bounding index designators for array. | |
buffer⇩ |
An FLI pointer. |
buffer-size⇩ |
A non-negative integer. |
target-buffer |
buffer or a new buffer. |
foreign-type⇩ |
A foreign type. |
The function get-primitive-array-region
copies from a Java array of primitive type to a buffer specified by a foreign pointer.
The function set-primitive-array-region
copies from a buffer specified by a foreign pointer to a Java array of primitive type.
buffer, if supplied, must be a foreign pointer pointing to a suitable buffer, which means large enough to receive the data in get-primitive-array-region
, or containing the desired data in set-primitive-array-region
.
start and end are bounding index designators for array, specifying the region to copy in number of elements.
buffer-size is used only when buffer is also supplied. buffer-size specifies the number of bytes to copy into buffer. If copying the required number of elements requires more bytes, get-primitive-array-region
signals an error. Note that buffer-size is specified in bytes, while start and end are specified in elements.
If buffer is not supplied to get-primitive-array-region
it creates a buffer of the correct size using fli:allocate-foreign-object
. In this case you will need to free the buffer using fli:free-foreign-object
when the program has finished with it.
get-primitive-array-region
copies the required number of elements into the buffer, and returns two values: the target buffer (either buffer or the new buffer) and the foreign type foreign-type corresponding to the Java primitive type (one of jbyte, jshort. jint. jlong, jfloat, jdouble, jboolean and jchar).
set-primitive-array-region
copies the required number of elements from buffer to array, and returns two values: t
and the foreign type.
These functions are useful when you need to pass the data to foreign code. If you need the data in Lisp, use lisp-array-to-primitive-array or primitive-array-to-lisp-array instead.
lisp-array-to-primitive-array
primitive-array-to-lisp-array
15.4 Working with Java arrays
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:46