Top Description Inners Fields Constructors Methods
com.kenai.jffi

public abstract Class MemoryIO

extends Object
Class Inheritance
Known Direct Subclasses
com.kenai.jffi.MemoryIO.NativeImpl, com.kenai.jffi.MemoryIO.CheckedNativeImpl, com.kenai.jffi.UnsafeMemoryIO
Imports
java.lang.reflect.Method

Provides facilities to access native memory from java.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private abstract static class
MemoryIO.NativeImpl

An implementation of MemoryIO using JNI methods.

private static class
MemoryIO.NativeImpl32

A 32 bit optimized implementation of MemoryIO using JNI.

private static class
MemoryIO.NativeImpl64

A 64 bit optimized implementation of MemoryIO using JNI.

private static class
MemoryIO.SingletonHolder

Holds a single instance of MemoryIO

Field Summary

Modifier and TypeField and Description
pack-priv static final long
ADDRESS_MASK

The address mask used to truncate 32bit addresses contained in long values

pack-priv final Foreign
foreign

A handle to the JNI accessor

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract void
_copyMemory(long
The source memory address.
src
,
long
The destination memory address.
dst
,
long
The number of bytes to copy.
size
)

Copies contents of a native memory location to another native memory location.

public final long

Returns:

The native address of the allocated memory.
allocateMemory
(long
The number of bytes of memory to allocate
size
,
boolean
Whether the memory should be cleared (each byte set to zero).
clear
)

Allocates native memory.

public final void
copyMemory(long
The source memory address.
src
,
long
The destination memory address.
dst
,
long
The number of bytes to copy.
size
)

Copies contents of a native memory location to another native memory location.

public final void
freeMemory(long
The address of the memory to release.
address
)

Releases memory allocated via allocateMemory back to the system.

public abstract long

Returns:

A long containing the value.
getAddress
(long
The memory location to get the value from.
address
)

Reads a native memory address from a native memory location.

public abstract byte

Returns:

A byte containing the value.
getByte
(long
The memory location to get the value from.
address
)

Reads an 8 bit integer from a native memory location.

public abstract void
getByteArray(long
The native memory address to copy the array from.
address
,
byte[]
The java array to copy.
data
,
int
The offset within the array to start copying to.
offset
,
int
The number of array elements to copy.
length
)

Reads a java byte array from native memory.

public abstract void
getCharArray(long
The native memory address to copy the array from.
address
,
char[]
The java array to copy.
data
,
int
The offset within the array to start copying to.
offset
,
int
The number of array elements to copy.
length
)

Reads a java char array from native memory.

public static MemoryIO
public final long

Returns:

The native memory address of the buffer contents, or null if not a direct buffer.
getDirectBufferAddress
(Buffer
A direct ByteBuffer to get the address of.
buffer
)

Gets the native memory address of a direct ByteBuffer

public abstract double

Returns:

A double containing the value.
getDouble
(long
The memory location to get the value from.
address
)

Reads a 64 bit floating point value from a native memory location.

public abstract void
getDoubleArray(long
The native memory address to copy the array from.
address
,
double[]
The java array to copy.
data
,
int
The offset within the array to start copying to.
offset
,
int
The number of array elements to copy.
length
)

Reads a java double array from native memory.

public abstract float

Returns:

A float containing the value.
getFloat
(long
The memory location to get the value from.
address
)

Reads a 32 bit floating point value from a native memory location.

public abstract void
getFloatArray(long
The native memory address to copy the array from.
address
,
float[]
The java array to copy.
data
,
int
The offset within the array to start copying to.
offset
,
int
The number of array elements to copy.
length
)

Reads a java float array from native memory.

public static MemoryIO

Returns:

A MemoryIO instance.
getInstance
()

Gets an instance of MemoryIO that can be used to access native memory.

public abstract int

Returns:

An int containing the value.
getInt
(long
The memory location to get the value from.
address
)

Reads a 32 bit integer from a native memory location.

public abstract void
getIntArray(long
The native memory address to copy the array from.
address
,
int[]
The java array to copy.
data
,
int
The offset within the array to start copying to.
offset
,
int
The number of array elements to copy.
length
)

Reads a java int array from native memory.

public abstract long

Returns:

A long containing the value.
getLong
(long
The memory location to get the value from.
address
)

Reads a 64 bit integer from a native memory location.

public abstract void
getLongArray(long
The native memory address to copy the array from.
address
,
long[]
The java array to copy.
data
,
int
The offset within the array to start copying to.
offset
,
int
The number of array elements to copy.
length
)

Reads a java long array from native memory.

public abstract short

Returns:

A short containing the value.
getShort
(long
The memory location to get the value from.
address
)

Reads a 16 bit integer from a native memory location.

public abstract void
getShortArray(long
The native memory address to copy the array from.
address
,
short[]
The java array to copy.
data
,
int
The offset within the array to start copying to.
offset
,
int
The number of array elements to copy.
length
)

Reads a java short array from native memory.

public abstract long

Returns:

The length of the string, in bytes.
getStringLength
(long
The native address of the string.
address
)

Gets the length of a native ascii or utf-8 string.

public abstract byte[]

Returns:

The byte array containing a copy of the native data. Any zero byte is stripped from the end.
getZeroTerminatedByteArray
(long
The address to read the data from.
address
)

Reads a byte array from native memory, stopping when a zero byte is found.

public abstract byte[]

Returns:

The byte array containing a copy of the native data. Any zero byte is stripped from the end.
getZeroTerminatedByteArray
(long
The address to read the data from.
address
,
int
The limit of the memory area to scan for a zero byte.
maxlen
)

Reads a byte array from native memory, stopping when a zero byte is found, or the maximum length is reached.

public final byte[]
getZeroTerminatedByteArray(long address, long maxlen)

Deprecated
public final long

Returns:

The offset from the memory address of the value, if found, else -1 (minus one).
indexOf
(long
The native memory address to start searching from.
address
,
byte
The value to search for.
value
)

Finds the location of a byte value in a native memory region.

public final long

Returns:

The offset from the memory address of the value, if found, else -1 (minus one).
indexOf
(long
The native memory address to start searching from.
address
,
byte
The value to search for.
value
,
int
The maximum number of bytes to search.
maxlen
)

Finds the location of a byte value in a native memory region.

pack-priv static boolean

Returns:

true if sun.misc.Unsafe is available and usable
isUnsafeAvailable
()

Determines the best Unsafe implementation to use.

public abstract long

Returns:

The address of the value, or 0 (zero) if not found.
memchr
(long
The native memory address to start searching.
address
,
int
The value to search for.
value
,
long
The size of the native memory region being searched.
size
)

Gets the address of a byte value in a native memory region.

public abstract void
memcpy(long
The destination memory address.
dst
,
long
The source memory address.
src
,
long
The number of bytes to copy.
size
)

Copies bytes from one memory location to another.

public abstract void
memmove(long
The destination memory address.
dst
,
long
The source memory address.
src
,
long
The number of bytes to copy.
size
)

Copies potentially overlapping memory areas.

public final void
memset(long
The address of start of the native memory.
address
,
int
The value to set the native memory to.
value
,
long
The number of bytes to set.
size
)

Sets a region of native memory to a specific byte value.

public final ByteBuffer

Returns:

A ByteBuffer representing the native memory region.
newDirectByteBuffer
(long
The start of the native memory region.
address
,
int
The size of the native memory region.
capacity
)

Creates a new Direct ByteBuffer for a native memory region.

private static MemoryIO

Returns:

An instance of MemoryIO
newMemoryIO
()

Creates a new instance of MemoryIO optimized for the current platform.

private static MemoryIO
private static MemoryIO
private static MemoryIO

Returns:

An instance of MemoryIO
newNativeImpl32
()

Creates a new JNI implementation of MemoryIO optimized for 32 bit platforms

private static MemoryIO

Returns:

An instance of MemoryIO
newNativeImpl64
()

Creates a new JNI implementation of MemoryIO optimized for 64 bit platforms

private static MemoryIO

Returns:

An instance of MemoryIO
newUnsafeImpl
()

Creates a new sun.misc.Unsafe implementation of MemoryIO

private static MemoryIO

Returns:

An instance of MemoryIO
newUnsafeImpl32
()

Creates a new sun.misc.Unsafe implementation of MemoryIO optimized for 32 bit platforms

private static MemoryIO

Returns:

An instance of MemoryIO
newUnsafeImpl64
()

Creates a new sun.misc.Unsafe implementation of MemoryIO optimized for 64 bit platforms

public abstract void
putAddress(long
The memory location to put the value.
address
,
long
The value to write to memory.
value
)

Writes a native memory address value to a native memory location.

public abstract void
putByte(long
The memory location to put the value.
address
,
byte
The value to write to memory.
value
)

Writes an 8 bit integer value to a native memory location.

public abstract void
putByteArray(long
The native memory address to copy the array to.
address
,
byte[]
The java array to copy.
data
,
int
The offset within the array to start copying from.
offset
,
int
The number of array elements to copy.
length
)

Writes a java byte array to native memory.

public abstract void
putCharArray(long
The native memory address to copy the array to.
address
,
char[]
The java array to copy.
data
,
int
The offset within the array to start copying from.
offset
,
int
The number of array elements to copy.
length
)

Writes a java char array to native memory.

public abstract void
putDouble(long
The memory location to put the value.
address
,
double
The value to write to memory.
value
)

Writes a 64 bit floating point value to a native memory location.

public abstract void
putDoubleArray(long
The native memory address to copy the array to.
address
,
double[]
The java array to copy.
data
,
int
The offset within the array to start copying from.
offset
,
int
The number of array elements to copy.
length
)

Writes a java double array to native memory.

public abstract void
putFloat(long
The memory location to put the value.
address
,
float
The value to write to memory.
value
)

Writes a 32 bit floating point value to a native memory location.

public abstract void
putFloatArray(long
The native memory address to copy the array to.
address
,
float[]
The java array to copy.
data
,
int
The offset within the array to start copying from.
offset
,
int
The number of array elements to copy.
length
)

Writes a java double array to native memory.

public abstract void
putInt(long
The memory location to put the value.
address
,
int
The value to write to memory.
value
)

Writes a 32 bit integer value to a native memory location.

public abstract void
putIntArray(long
The native memory address to copy the array to.
address
,
int[]
The java array to copy.
data
,
int
The offset within the array to start copying from.
offset
,
int
The number of array elements to copy.
length
)

Writes a java int array to native memory.

public abstract void
putLong(long
The memory location to put the value.
address
,
long
The value to write to memory.
value
)

Writes a 64 bit integer value to a native memory location.

public abstract void
putLongArray(long
The native memory address to copy the array to.
address
,
long[]
The java array to copy.
data
,
int
The offset within the array to start copying from.
offset
,
int
The number of array elements to copy.
length
)

Writes a java long array to native memory.

public abstract void
putShort(long
The memory location to put the value.
address
,
short
The value to write to memory.
value
)

Writes a 16 bit integer value to a native memory location.

public abstract void
putShortArray(long
The native memory address to copy the array to.
address
,
short[]
The java array to copy.
data
,
int
The offset within the array to start copying from.
offset
,
int
The number of array elements to copy.
length
)

Writes a java short array to native memory.

public abstract void
putZeroTerminatedByteArray(long
The address to copy to.
address
,
byte[]
The byte array to copy to native memory
data
,
int
The offset within the byte array to begin copying from
offset
,
int
The number of bytes to copy to native memory
length
)

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.

public abstract void
setMemory(long
The address of start of the native memory.
address
,
long
The number of bytes to set.
size
,
byte
The value to set the native memory to.
value
)

Sets a region of native memory to a specific byte value.

private static void
verifyAccessor(Class<T>
The class of sun.misc.Unsafe
unsafeClass
,
Class<T>
The class of the primitive type.
primitive
)

Verifies that there is are accessor functions (get,put) for a particular primitive type in the sun.misc.Unsafe class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait