Package com.kenai.jffi
Class MemoryIO.CheckedNativeImpl
- java.lang.Object
-
- com.kenai.jffi.MemoryIO
-
- com.kenai.jffi.MemoryIO.CheckedNativeImpl
-
-
Field Summary
-
Fields inherited from class com.kenai.jffi.MemoryIO
ADDRESS_MASK, foreign
-
-
Constructor Summary
Constructors Modifier Constructor Description private
CheckedNativeImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
_copyMemory(long src, long dst, long size)
Copies contents of a native memory location to another native memory location.long
getAddress(long address)
Reads a native memory address from a native memory location.byte
getByte(long address)
Reads an 8 bit integer from a native memory location.void
getByteArray(long address, byte[] data, int offset, int length)
Reads a java byte array from native memory.void
getCharArray(long address, char[] data, int offset, int length)
Reads a java char array from native memory.double
getDouble(long address)
Reads a 64 bit floating point value from a native memory location.void
getDoubleArray(long address, double[] data, int offset, int length)
Reads a java double array from native memory.float
getFloat(long address)
Reads a 32 bit floating point value from a native memory location.void
getFloatArray(long address, float[] data, int offset, int length)
Reads a java float array from native memory.int
getInt(long address)
Reads a 32 bit integer from a native memory location.void
getIntArray(long address, int[] data, int offset, int length)
Reads a java int array from native memory.long
getLong(long address)
Reads a 64 bit integer from a native memory location.void
getLongArray(long address, long[] data, int offset, int length)
Reads a java long array from native memory.short
getShort(long address)
Reads a 16 bit integer from a native memory location.void
getShortArray(long address, short[] data, int offset, int length)
Reads a java short array from native memory.long
getStringLength(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.long
memchr(long address, int value, long size)
Gets the address of a byte value in a native memory region.void
memcpy(long dst, long src, long size)
Copies bytes from one memory location to another.void
memmove(long dst, long src, long size)
Copies potentially overlapping memory areas.void
putAddress(long address, long value)
Writes a native memory address value to a native memory location.void
putByte(long address, byte value)
Writes an 8 bit integer value to a native memory location.void
putByteArray(long address, byte[] data, int offset, int length)
Writes a java byte array to native memory.void
putCharArray(long address, char[] data, int offset, int length)
Writes a java char array to native memory.void
putDouble(long address, double value)
Writes a 64 bit floating point value to a native memory location.void
putDoubleArray(long address, double[] data, int offset, int length)
Writes a java double array to native memory.void
putFloat(long address, float value)
Writes a 32 bit floating point value to a native memory location.void
putFloatArray(long address, float[] data, int offset, int length)
Writes a java double array to native memory.void
putInt(long address, int value)
Writes a 32 bit integer value to a native memory location.void
putIntArray(long address, int[] data, int offset, int length)
Writes a java int array to native memory.void
putLong(long address, long value)
Writes a 64 bit integer value to a native memory location.void
putLongArray(long address, long[] data, int offset, int length)
Writes a java long array to native memory.void
putShort(long address, short value)
Writes a 16 bit integer value to a native memory location.void
putShortArray(long address, short[] data, int offset, int length)
Writes a java short array to native memory.void
putZeroTerminatedByteArray(long address, byte[] data, int offset, int length)
Copies a java byte array to native memory and appends a NUL terminating byte.void
setMemory(long address, 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, getCheckedInstance, getDirectBufferAddress, getInstance, getZeroTerminatedByteArray, indexOf, indexOf, isUnsafeAvailable, memset, newDirectByteBuffer
-
-
-
-
Method Detail
-
getByte
public final byte getByte(long address)
Description copied from class:MemoryIO
Reads an 8 bit integer from a native memory location.
-
getShort
public final short getShort(long address)
Description copied from class:MemoryIO
Reads a 16 bit integer from a native memory location.
-
getInt
public final int getInt(long address)
Description copied from class:MemoryIO
Reads a 32 bit integer from a native memory location.
-
getLong
public final long getLong(long address)
Description copied from class:MemoryIO
Reads a 64 bit integer from a native memory location.
-
getFloat
public final float getFloat(long address)
Description copied from class:MemoryIO
Reads a 32 bit floating point value from a native memory location.
-
getDouble
public final double getDouble(long address)
Description copied from class:MemoryIO
Reads a 64 bit floating point value from a native memory location.
-
putByte
public final void putByte(long address, byte value)
Description copied from class:MemoryIO
Writes an 8 bit integer value to a native memory location.
-
putShort
public final void putShort(long address, short value)
Description copied from class:MemoryIO
Writes a 16 bit integer value to a native memory location.
-
putInt
public final void putInt(long address, int value)
Description copied from class:MemoryIO
Writes a 32 bit integer value to a native memory location.
-
putLong
public final void putLong(long address, long value)
Description copied from class:MemoryIO
Writes a 64 bit integer value to a native memory location.
-
putFloat
public final void putFloat(long address, float value)
Description copied from class:MemoryIO
Writes a 32 bit floating point value to a native memory location.
-
putDouble
public final void putDouble(long address, double value)
Description copied from class:MemoryIO
Writes a 64 bit floating point value to a native memory location.
-
setMemory
public final void setMemory(long address, long size, byte value)
Description copied from class:MemoryIO
Sets a region of native memory to a specific byte value.
-
_copyMemory
public final void _copyMemory(long src, long dst, long size)
Description copied from class:MemoryIO
Copies contents of a native memory location to another native memory location.- Specified by:
_copyMemory
in classMemoryIO
- Parameters:
src
- The source memory address.dst
- The destination memory address.size
- The number of bytes to copy.
-
getAddress
public final long getAddress(long address)
Description copied from class:MemoryIO
Reads a native memory address from a native memory location.- Specified by:
getAddress
in classMemoryIO
- Parameters:
address
- The memory location to get the value from.- Returns:
- A long containing the value.
-
putAddress
public final void putAddress(long address, long value)
Description copied from class:MemoryIO
Writes a native memory address value to a native memory location.- Specified by:
putAddress
in classMemoryIO
- Parameters:
address
- The memory location to put the value.value
- The value to write to memory.
-
memcpy
public final void memcpy(long dst, long src, long size)
Description copied from class:MemoryIO
Copies 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:MemoryIO
Copies potentially overlapping memory areas.
-
memchr
public final long memchr(long address, int value, long size)
Description copied from class:MemoryIO
Gets 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:MemoryIO
Writes a java byte array to native memory.- Specified by:
putByteArray
in 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:MemoryIO
Reads a java byte array from native memory.- Specified by:
getByteArray
in 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:MemoryIO
Writes a java char array to native memory.- Specified by:
putCharArray
in 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:MemoryIO
Reads a java char array from native memory.- Specified by:
getCharArray
in 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:MemoryIO
Writes a java short array to native memory.- Specified by:
putShortArray
in 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:MemoryIO
Reads a java short array from native memory.- Specified by:
getShortArray
in 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:MemoryIO
Writes a java int array to native memory.- Specified by:
putIntArray
in 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:MemoryIO
Reads a java int array from native memory.- Specified by:
getIntArray
in 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:MemoryIO
Writes a java long array to native memory.- Specified by:
putLongArray
in 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:MemoryIO
Reads a java long array from native memory.- Specified by:
getLongArray
in 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:MemoryIO
Writes a java double array to native memory.- Specified by:
putFloatArray
in 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:MemoryIO
Reads a java float array from native memory.- Specified by:
getFloatArray
in 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:MemoryIO
Writes a java double array to native memory.- Specified by:
putDoubleArray
in 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:MemoryIO
Reads a java double array from native memory.- Specified by:
getDoubleArray
in 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:MemoryIO
Gets the length of a native ascii or utf-8 string.- Specified by:
getStringLength
in 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:MemoryIO
Reads 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:
getZeroTerminatedByteArray
in 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:MemoryIO
Reads 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:
getZeroTerminatedByteArray
in 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:MemoryIO
Copies 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:
putZeroTerminatedByteArray
in 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
-
-