Package com.kenai.jffi
Class UnsafeMemoryIO
- java.lang.Object
-
- com.kenai.jffi.MemoryIO
-
- com.kenai.jffi.UnsafeMemoryIO
-
public abstract class UnsafeMemoryIO extends MemoryIO
An implementation ofMemoryIOusing sun.misc.Unsafe
-
-
Field Summary
Fields Modifier and Type Field Description protected static sun.misc.Unsafeunsafe
-
Constructor Summary
Constructors Constructor Description UnsafeMemoryIO()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void_copyMemory(long src, long dst, long size)bytegetByte(long address)Reads an 8 bit integer from a native memory location.voidgetByteArray(long address, byte[] data, int offset, int length)Reads a java byte array from native memory.voidgetCharArray(long address, char[] data, int offset, int length)Reads a java char array from native memory.doublegetDouble(long address)Reads a 64 bit floating point value from a native memory location.voidgetDoubleArray(long address, double[] data, int offset, int length)Reads a java double array from native memory.floatgetFloat(long address)Reads a 32 bit floating point value from a native memory location.voidgetFloatArray(long address, float[] data, int offset, int length)Reads a java float array from native memory.intgetInt(long address)Reads a 32 bit integer from a native memory location.voidgetIntArray(long address, int[] data, int offset, int length)Reads a java int array from native memory.longgetLong(long address)Reads a 64 bit integer from a native memory location.voidgetLongArray(long address, long[] data, int offset, int length)Reads a java long array from native memory.shortgetShort(long address)Reads a 16 bit integer from a native memory location.voidgetShortArray(long address, short[] data, int offset, int length)Reads a java short array from native memory.longgetStringLength(long address)Gets the length of a native ascii or utf-8 string.byte[]getZeroTerminatedByteArray(long address)Reads a byte array from native memory, stopping when a zero byte is found.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.longmemchr(long address, int value, long size)Gets the address of a byte value in a native memory region.voidmemcpy(long dst, long src, long size)Copies bytes from one memory location to another.voidmemmove(long dst, long src, long size)Copies potentially overlapping memory areas.voidputByte(long address, byte value)Writes an 8 bit integer value to a native memory location.voidputByteArray(long address, byte[] data, int offset, int length)Writes a java byte array to native memory.voidputCharArray(long address, char[] data, int offset, int length)Writes a java char array to native memory.voidputDouble(long address, double value)Writes a 64 bit floating point value to a native memory location.voidputDoubleArray(long address, double[] data, int offset, int length)Writes a java double array to native memory.voidputFloat(long address, float value)Writes a 32 bit floating point value to a native memory location.voidputFloatArray(long address, float[] data, int offset, int length)Writes a java double array to native memory.voidputInt(long address, int value)Writes a 32 bit integer value to a native memory location.voidputIntArray(long address, int[] data, int offset, int length)Writes a java int array to native memory.voidputLong(long address, long value)Writes a 64 bit integer value to a native memory location.voidputLongArray(long address, long[] data, int offset, int length)Writes a java long array to native memory.voidputShort(long address, short value)Writes a 16 bit integer value to a native memory location.voidputShortArray(long address, short[] data, int offset, int length)Writes a java short array to native memory.voidputZeroTerminatedByteArray(long address, byte[] data, int offset, int length)Copies a java byte array to native memory and appends a NUL terminating byte.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
-
-
-
-
Method Detail
-
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
-
-