All Manuals > LispWorks® User Guide and Reference Manual > 39 The LW-JI Package

get-primitive-array-region

set-primitive-array-region Functions

Summary

Copy between a Java array of primitive type and a buffer specified by a foreign pointer.

Package

lw-ji

Signatures

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

Arguments
array
A Java array of primitive type.
start, end
Bounding index designators for array.
buffer
An FLI pointer.
buffer-size
A non-negative integer.
Values
target-buffer
buffer or a new buffer.
foreign-type
A foreign type.
Description

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.

Notes

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.

See also

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