This class is a performance optimization aid which provides the low-level access to arrays. It contains the following groups of methods:
- lockArray/lockArrayLong methods - used to lock the memory location for the primitive type arrays for either short or long amounts of time such that their contents can be directly accessed in the memory. Typically, this is used to pass java arrays as arguments to native functions. One array can not be locked for the short and long period of time simultaneously.
- set/getElement methods - used to read and write individual array elements bypassing the bounds checks.
- getArrayBaseOffset/ElementSize methods - used to obtain information about arrays layout in the memory.
The typical implementations of the {@link #lockArrayShort(Object)}and {@link #lockArrayLong(Object)}methods would instruct a virtual machine that the given array should stay unmovable for a certain period of time (i.e. until it is released by {@link LockedArray#release()}call). On virtual machines which do not support the unmovable arrays for some reason, functionality of the
lockArray/release
pair still can be emulated by copying the array content into the native heap and back. However, whatever implementation exists, the {@link LockedArray#getAddress()}method must return the memory location which is applicable for direct memory access operations, such as the ones provided by {@link MemoryAccessor}class.
A typical usage example for the locked arrays would look like that:
ArrayAccessor aa = AccessorFactory.getArrayAccessor(); byte[] bytearr = (byte[])aa.createArray(Byte.TYPE, 1024); ...fill the bytearr ... LockedArray la = aa.lockArrayShort(bytearr); int pixmap = x11.XCreateBitmapFromData(display, wnd, la.getAddress(), width, height); la.release();