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

NextPrevUpTopContentsIndex

primitive-array-to-lisp-array

lisp-array-to-primitive-array

Functions
Summary

Copy elements between a Java primitive array and a Lisp array of matching type.

Package

lw-ji

Signature

primitive-array-to-lisp-array p-array &key start end target-start target-end lisp-array => l-result

Signature

lisp-array-to-primitive-array l-array &key start end target-start target-end primitive-array => p-result

Arguments

p-array

A Java array of primitive type.

start, end

Bounding index designators.

target-start, target-end

Bounding index designators.

lisp-array

A Lisp array of an acceptable type, or nil.

l-array

A Lisp array of an acceptable type.

primitive-array

A Java array of primitive type, or nil.

Values

l-result

lisp-array or a new Lisp array.

p-result

primitive-array or a new primitive array.

Description

The function primitive-array-to-lisp-array takes a Java array p-array of primitive type and copies elements from it to a Lisp array of matching type. The target lisp-array is created by default, but can also be supplied as an argument.

The function lisp-array-to-primitive-array takes a Lisp array l-array of an acceptable Lisp type and copies elements from it to a Java array of matching type. The target primitive-array is created by default, but can also be supplied as an argument.

start and end are bounding index designators for the source p-array or l-array, specifying the range to copy.

target-start and target-end are used only if the target is supplied (by lisp-array or primitive-array). They specify the start and end for copying in the target. The actual number of elements copied is the minimum of the lengths specified for the source and for the target.

If the target (lisp-array or primitive-array) is not supplied, these functions create an array of the correct type and the copy length, and copy into it.

The Lisp array that is passed to lisp-array-to-primitive-array must be of one of the types listed below, and when the target array is supplied, its type must match the type of the source array according to the table below, except that cl:base-char array (cl:simple-base-string) is acceptable when the Java side is byte.

Correspondence between Java primitive and Lisp array element types
 

Java primitive type

Keyword
(result of java-array-element-type)

Lisp type
(result of cl:array-element-type)

byte

:byte

(signed-byte 8)

short

:short

(signed-byte 16)

int

:int

(signed-byte 32)

long

:long

(signed-byte 64)

double

:double

double-float

float

:float

single-float

char

:char

(unsigned-byte 16)

boolean

:boolean

(unsigned-byte 8)

For boolean, 1 is true and 0 is false.

Notes

For a large number of elements, these functions are much faster than jvref. If the primitive data is needed for passing to or from foreign functions, use get-primitive-array-region and set-primitive-array-region instead. These functions work only on arrays with one dimension with primitive element type. For non-primitive arrays of one dimension you can use map-java-object-array.

See also

get-primitive-array-region
set-primitive-array-region
map-java-object-array
jvref
jaref
Working with Java arrays


LispWorks User Guide and Reference Manual - 20 Sep 2017

NextPrevUpTopContentsIndex