Package com.kenai.jffi
Class UnsafeMemoryIO
java.lang.Object
com.kenai.jffi.MemoryIO
com.kenai.jffi.UnsafeMemoryIO
An implementation of
MemoryIO using sun.misc.Unsafe-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void_copyMemory(long src, long dst, long size) final bytegetByte(long address) Reads an 8 bit integer from a native memory location.final voidgetByteArray(long address, byte[] data, int offset, int length) Reads a java byte array from native memory.final voidgetCharArray(long address, char[] data, int offset, int length) Reads a java char array from native memory.final doublegetDouble(long address) Reads a 64 bit floating point value from a native memory location.final voidgetDoubleArray(long address, double[] data, int offset, int length) Reads a java double array from native memory.final floatgetFloat(long address) Reads a 32 bit floating point value from a native memory location.final voidgetFloatArray(long address, float[] data, int offset, int length) Reads a java float array from native memory.final intgetInt(long address) Reads a 32 bit integer from a native memory location.final voidgetIntArray(long address, int[] data, int offset, int length) Reads a java int array from native memory.final longgetLong(long address) Reads a 64 bit integer from a native memory location.final voidgetLongArray(long address, long[] data, int offset, int length) Reads a java long array from native memory.final shortgetShort(long address) Reads a 16 bit integer from a native memory location.final voidgetShortArray(long address, short[] data, int offset, int length) Reads a java short array from native memory.final longgetStringLength(long address) Gets the length of a native ascii or utf-8 string.final byte[]getZeroTerminatedByteArray(long address) Reads a byte array from native memory, stopping when a zero byte is found.final byte[]getZeroTerminatedByteArray(long address, int maxlen) Reads a byte array from native memory, stopping when a zero byte is found, or the maximum length is reached.final longmemchr(long address, int value, long size) Gets the address of a byte value in a native memory region.final voidmemcpy(long dst, long src, long size) Copies bytes from one memory location to another.final voidmemmove(long dst, long src, long size) Copies potentially overlapping memory areas.final voidputByte(long address, byte value) Writes an 8 bit integer value to a native memory location.final voidputByteArray(long address, byte[] data, int offset, int length) Writes a java byte array to native memory.final voidputCharArray(long address, char[] data, int offset, int length) Writes a java char array to native memory.final voidputDouble(long address, double value) Writes a 64 bit floating point value to a native memory location.final voidputDoubleArray(long address, double[] data, int offset, int length) Writes a java double array to native memory.final voidputFloat(long address, float value) Writes a 32 bit floating point value to a native memory location.final voidputFloatArray(long address, float[] data, int offset, int length) Writes a java double array to native memory.final voidputInt(long address, int value) Writes a 32 bit integer value to a native memory location.final voidputIntArray(long address, int[] data, int offset, int length) Writes a java int array to native memory.final voidputLong(long address, long value) Writes a 64 bit integer value to a native memory location.final voidputLongArray(long address, long[] data, int offset, int length) Writes a java long array to native memory.final voidputShort(long address, short value) Writes a 16 bit integer value to a native memory location.final voidputShortArray(long address, short[] data, int offset, int length) Writes a java short array to native memory.final voidputZeroTerminatedByteArray(long address, byte[] data, int offset, int length) Copies a java byte array to native memory and appends a NUL terminating byte.final voidsetMemory(long src, long size, byte value) Sets a region of native memory to a specific byte value.Methods inherited from class com.kenai.jffi.MemoryIO
allocateMemory, copyMemory, freeMemory, getAddress, getCheckedInstance, getDirectBufferAddress, getInstance, getZeroTerminatedByteArray, indexOf, indexOf, memset, newDirectByteBuffer, putAddress
-
Field Details
-
unsafe
protected static sun.misc.Unsafe unsafe
-
-
Constructor Details
-
UnsafeMemoryIO
public UnsafeMemoryIO()
-
-
Method Details
-
getByte
public final byte getByte(long address) Description copied from class:MemoryIOReads an 8 bit integer from a native memory location. -
getShort
public final short getShort(long address) Description copied from class:MemoryIOReads a 16 bit integer from a native memory location. -
getInt
public final int getInt(long address) Description copied from class:MemoryIOReads a 32 bit integer from a native memory location. -
getLong
public final long getLong(long address) Description copied from class:MemoryIOReads a 64 bit integer from a native memory location. -
getFloat
public final float getFloat(long address) Description copied from class:MemoryIOReads a 32 bit floating point value from a native memory location. -
getDouble
public final double getDouble(long address) Description copied from class:MemoryIOReads a 64 bit floating point value from a native memory location. -
putByte
public final void putByte(long address, byte value) Description copied from class:MemoryIOWrites an 8 bit integer value to a native memory location. -
putShort
public final void putShort(long address, short value) Description copied from class:MemoryIOWrites a 16 bit integer value to a native memory location. -
putInt
public final void putInt(long address, int value) Description copied from class:MemoryIOWrites a 32 bit integer value to a native memory location. -
putLong
public final void putLong(long address, long value) Description copied from class:MemoryIOWrites a 64 bit integer value to a native memory location. -
putFloat
public final void putFloat(long address, float value) Description copied from class:MemoryIOWrites a 32 bit floating point value to a native memory location. -
putDouble
public final void putDouble(long address, double value) Description copied from class:MemoryIOWrites a 64 bit floating point value to a native memory location. -
_copyMemory
public final void _copyMemory(long src, long dst, long size) -
setMemory
public final void setMemory(long src, long size, byte value) Description copied from class:MemoryIOSets a region of native memory to a specific byte value. -
memcpy
public final void memcpy(long dst, long src, long size) Description copied from class:MemoryIOCopies bytes from one memory location to another. The memory areas -
memmove
public final void memmove(long dst, long src, long size) Description copied from class:MemoryIOCopies potentially overlapping memory areas. -
memchr
public final long memchr(long address, int value, long size) Description copied from class:MemoryIOGets the address of a byte value in a native memory region. -
putByteArray
public final void putByteArray(long address, byte[] data, int offset, int length) Description copied from class:MemoryIOWrites a java byte array to native memory.- Specified by:
putByteArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array to.data- The java array to copy.offset- The offset within the array to start copying from.length- The number of array elements to copy.
-
getByteArray
public final void getByteArray(long address, byte[] data, int offset, int length) Description copied from class:MemoryIOReads a java byte array from native memory.- Specified by:
getByteArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array from.data- The java array to copy.offset- The offset within the array to start copying to.length- The number of array elements to copy.
-
putCharArray
public final void putCharArray(long address, char[] data, int offset, int length) Description copied from class:MemoryIOWrites a java char array to native memory.- Specified by:
putCharArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array to.data- The java array to copy.offset- The offset within the array to start copying from.length- The number of array elements to copy.
-
getCharArray
public final void getCharArray(long address, char[] data, int offset, int length) Description copied from class:MemoryIOReads a java char array from native memory.- Specified by:
getCharArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array from.data- The java array to copy.offset- The offset within the array to start copying to.length- The number of array elements to copy.
-
putShortArray
public final void putShortArray(long address, short[] data, int offset, int length) Description copied from class:MemoryIOWrites a java short array to native memory.- Specified by:
putShortArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array to.data- The java array to copy.offset- The offset within the array to start copying from.length- The number of array elements to copy.
-
getShortArray
public final void getShortArray(long address, short[] data, int offset, int length) Description copied from class:MemoryIOReads a java short array from native memory.- Specified by:
getShortArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array from.data- The java array to copy.offset- The offset within the array to start copying to.length- The number of array elements to copy.
-
putIntArray
public final void putIntArray(long address, int[] data, int offset, int length) Description copied from class:MemoryIOWrites a java int array to native memory.- Specified by:
putIntArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array to.data- The java array to copy.offset- The offset within the array to start copying from.length- The number of array elements to copy.
-
getIntArray
public final void getIntArray(long address, int[] data, int offset, int length) Description copied from class:MemoryIOReads a java int array from native memory.- Specified by:
getIntArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array from.data- The java array to copy.offset- The offset within the array to start copying to.length- The number of array elements to copy.
-
putLongArray
public final void putLongArray(long address, long[] data, int offset, int length) Description copied from class:MemoryIOWrites a java long array to native memory.- Specified by:
putLongArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array to.data- The java array to copy.offset- The offset within the array to start copying from.length- The number of array elements to copy.
-
getLongArray
public final void getLongArray(long address, long[] data, int offset, int length) Description copied from class:MemoryIOReads a java long array from native memory.- Specified by:
getLongArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array from.data- The java array to copy.offset- The offset within the array to start copying to.length- The number of array elements to copy.
-
putFloatArray
public final void putFloatArray(long address, float[] data, int offset, int length) Description copied from class:MemoryIOWrites a java double array to native memory.- Specified by:
putFloatArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array to.data- The java array to copy.offset- The offset within the array to start copying from.length- The number of array elements to copy.
-
getFloatArray
public final void getFloatArray(long address, float[] data, int offset, int length) Description copied from class:MemoryIOReads a java float array from native memory.- Specified by:
getFloatArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array from.data- The java array to copy.offset- The offset within the array to start copying to.length- The number of array elements to copy.
-
putDoubleArray
public final void putDoubleArray(long address, double[] data, int offset, int length) Description copied from class:MemoryIOWrites a java double array to native memory.- Specified by:
putDoubleArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array to.data- The java array to copy.offset- The offset within the array to start copying from.length- The number of array elements to copy.
-
getDoubleArray
public final void getDoubleArray(long address, double[] data, int offset, int length) Description copied from class:MemoryIOReads a java double array from native memory.- Specified by:
getDoubleArrayin classMemoryIO- Parameters:
address- The native memory address to copy the array from.data- The java array to copy.offset- The offset within the array to start copying to.length- The number of array elements to copy.
-
getStringLength
public final long getStringLength(long address) Description copied from class:MemoryIOGets the length of a native ascii or utf-8 string.- Specified by:
getStringLengthin classMemoryIO- Parameters:
address- The native address of the string.- Returns:
- The length of the string, in bytes.
-
getZeroTerminatedByteArray
public final byte[] getZeroTerminatedByteArray(long address) Description copied from class:MemoryIOReads a byte array from native memory, stopping when a zero byte is found. This can be used to read ascii or utf-8 strings from native memory.- Specified by:
getZeroTerminatedByteArrayin classMemoryIO- Parameters:
address- The address to read the data from.- Returns:
- The byte array containing a copy of the native data. Any zero byte is stripped from the end.
-
getZeroTerminatedByteArray
public final byte[] getZeroTerminatedByteArray(long address, int maxlen) Description copied from class:MemoryIOReads a byte array from native memory, stopping when a zero byte is found, or the maximum length is reached. This can be used to read ascii or utf-8 strings from native memory.- Specified by:
getZeroTerminatedByteArrayin classMemoryIO- Parameters:
address- The address to read the data from.maxlen- The limit of the memory area to scan for a zero byte.- Returns:
- The byte array containing a copy of the native data. Any zero byte is stripped from the end.
-
putZeroTerminatedByteArray
public final void putZeroTerminatedByteArray(long address, byte[] data, int offset, int length) Description copied from class:MemoryIOCopies a java byte array to native memory and appends a NUL terminating byte. Note A total of length + 1 bytes is written to native memory.- Specified by:
putZeroTerminatedByteArrayin classMemoryIO- Parameters:
address- The address to copy to.data- The byte array to copy to native memoryoffset- The offset within the byte array to begin copying fromlength- The number of bytes to copy to native memory
-