public interface Memory
In contrast to the java.nio.ByteBuffer classes, which were designed for native streaming I/O and include concepts such as position, limit, mark, flip and rewind, this interface specifically bypasses these concepts and instead provides a rich collection of primitive, bit, array and copy methods that access the data directly from a single byte offset.
| Modifier and Type | Method and Description |
|---|---|
Object |
array()
Returns the backing on-heap primitive array if there is one, otherwise returns null
|
Memory |
asReadOnlyMemory()
Returns a read-only version of this memory
|
ByteBuffer |
byteBuffer()
Returns the backing ByteBuffer if there is one, otherwise returns null
|
void |
clear()
Clears all bytes of this Memory to zero
|
void |
clear(long offsetBytes,
long lengthBytes)
Clears a portion of this Memory to zero.
|
void |
clearBits(long offsetBytes,
byte bitMask)
Clears the bits defined by the bitMask
|
void |
copy(long srcOffsetBytes,
long dstOffsetBytes,
long lengthBytes)
Copies bytes from a source region of this Memory to a destination region of this Memory.
|
void |
fill(byte value)
Fills all bytes of this Memory region to the given byte value.
|
void |
fill(long offsetBytes,
long lengthBytes,
byte value)
Fills a portion of this Memory region to the given byte value.
|
long |
getAddress(long offsetBytes)
Returns the start address of this Memory relative to its parent plus the offset in bytes.
|
int |
getAndAddInt(long offsetBytes,
int delta)
Atomically adds the given value to the integer located at offsetBytes.
|
long |
getAndAddLong(long offsetBytes,
long delta)
Atomically adds the given value to the long located at offsetBytes.
|
int |
getAndSetInt(long offsetBytes,
int newValue)
Atomically exchanges the given value with the current value located at offsetBytes.
|
long |
getAndSetLong(long offsetBytes,
long newValue)
Atomically exchanges the given value with the current value located at offsetBytes.
|
boolean |
getBoolean(long offsetBytes)
Gets the boolean value at the given offset
|
void |
getBooleanArray(long offsetBytes,
boolean[] dstArray,
int dstOffset,
int length)
Gets the boolean array at the given offset
|
byte |
getByte(long offsetBytes)
Gets the byte at the given offset
|
void |
getByteArray(long offsetBytes,
byte[] dstArray,
int dstOffset,
int length)
Gets the byte array at the given offset
|
long |
getCapacity()
Gets the capacity of this Memory in bytes
|
char |
getChar(long offsetBytes)
Gets the char at the given offset
|
void |
getCharArray(long offsetBytes,
char[] dstArray,
int dstOffset,
int length)
Gets the char array at the given offset
|
long |
getCumulativeOffset(long offsetBytes)
Returns the cumulative offset in bytes of this Memory from the base Memory including the given
offset.
|
double |
getDouble(long offsetBytes)
Gets the double at the given offset
|
void |
getDoubleArray(long offsetBytes,
double[] dstArray,
int dstOffset,
int length)
Gets the double array at the given offset
|
float |
getFloat(long offsetBytes)
Gets the float at the given offset
|
void |
getFloatArray(long offsetBytes,
float[] dstArray,
int dstOffset,
int length)
Gets the float array at the given offset
|
int |
getInt(long offsetBytes)
Gets the int at the given offset
|
void |
getIntArray(long offsetBytes,
int[] dstArray,
int dstOffset,
int length)
Gets the int array at the given offset
|
long |
getLong(long offsetBytes)
Gets the long at the given offset
|
void |
getLongArray(long offsetBytes,
long[] dstArray,
int dstOffset,
int length)
Gets the long array at the given offset
|
MemoryRequest |
getMemoryRequest()
Returns a MemoryRequest or null
|
NativeMemory |
getNativeMemory()
Returns the root NativeMemory, which could also be the derived MemoryMappedFile or AllocMemory.
|
Object |
getParent()
Gets the parent Memory or backing array.
|
short |
getShort(long offsetBytes)
Gets the short at the given offset
|
void |
getShortArray(long offsetBytes,
short[] dstArray,
int dstOffset,
int length)
Gets the short array at the given offset
|
boolean |
hasArray()
Returns true if this Memory is backed by an on-heap primitive array
|
boolean |
hasByteBuffer()
Returns true if this Memory is backed by a ByteBuffer
|
boolean |
isAllBitsClear(long offsetBytes,
byte bitMask)
Returns true if all bits defined by the bitMask are clear
|
boolean |
isAllBitsSet(long offsetBytes,
byte bitMask)
Returns true if all bits defined by the bitMask are set
|
boolean |
isAllocated()
Returns true if this Memory has a capacity greater than zero
|
boolean |
isAnyBitsClear(long offsetBytes,
byte bitMask)
Returns true if any bits defined by the bitMask are clear
|
boolean |
isAnyBitsSet(long offsetBytes,
byte bitMask)
Returns true if any bits defined by the bitMask are set
|
boolean |
isDirect()
Returns true if the backing memory is direct (off-heap) memory.
|
boolean |
isReadOnly()
Returns true if this Memory is read only
|
void |
putBoolean(long offsetBytes,
boolean value)
Puts the boolean value at the given offset
|
void |
putBooleanArray(long offsetBytes,
boolean[] srcArray,
int srcOffset,
int length)
Puts the boolean array at the given offset
|
void |
putByte(long offsetBytes,
byte value)
Puts the byte value at the given offset
|
void |
putByteArray(long offsetBytes,
byte[] srcArray,
int srcOffset,
int length)
Puts the byte array at the given offset
|
void |
putChar(long offsetBytes,
char value)
Puts the char value at the given offset
|
void |
putCharArray(long offsetBytes,
char[] srcArray,
int srcOffset,
int length)
Puts the char array at the given offset
|
void |
putDouble(long offsetBytes,
double value)
Puts the double value at the given offset
|
void |
putDoubleArray(long offsetBytes,
double[] srcArray,
int srcOffset,
int length)
Puts the double array at the given offset
|
void |
putFloat(long offsetBytes,
float value)
Puts the float value at the given offset
|
void |
putFloatArray(long offsetBytes,
float[] srcArray,
int srcOffset,
int length)
Puts the float array at the given offset
|
void |
putInt(long offsetBytes,
int value)
Puts the int value at the given offset
|
void |
putIntArray(long offsetBytes,
int[] srcArray,
int srcOffset,
int length)
Puts the int array at the given offset
|
void |
putLong(long offsetBytes,
long value)
Puts the long value at the given offset
|
void |
putLongArray(long offsetBytes,
long[] srcArray,
int srcOffset,
int length)
Puts the long array at the given offset
|
void |
putShort(long offsetBytes,
short value)
Puts the short value at the given offset
|
void |
putShortArray(long offsetBytes,
short[] srcArray,
int srcOffset,
int length)
Puts the short array at the given offset
|
void |
setBits(long offsetBytes,
byte bitMask)
Sets the bits defined by the bitMask
|
void |
setMemoryRequest(MemoryRequest memReq)
Sets a MemoryRequest
|
String |
toHexString(String header,
long offsetBytes,
int lengthBytes)
Returns a formatted hex string of an area of this Memory.
|
void clear()
void clear(long offsetBytes,
long lengthBytes)
offsetBytes - offset bytes relative to this Memory startlengthBytes - the length in bytesvoid clearBits(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory start.bitMask - the bits set to one will be clearedvoid copy(long srcOffsetBytes,
long dstOffsetBytes,
long lengthBytes)
srcOffsetBytes - the source offsetdstOffsetBytes - the destintaion offsetlengthBytes - the number of bytes to copyvoid fill(byte value)
value - the given byte valuevoid fill(long offsetBytes,
long lengthBytes,
byte value)
offsetBytes - offset bytes relative to this Memory startlengthBytes - the length in bytesvalue - the given byte valueint getAndAddInt(long offsetBytes,
int delta)
offsetBytes - offset bytes relative to this Memory startdelta - the amount to addlong getAndAddLong(long offsetBytes,
long delta)
offsetBytes - offset bytes relative to this Memory startdelta - the amount to addint getAndSetInt(long offsetBytes,
int newValue)
offsetBytes - offset bytes relative to this Memory startnewValue - new valuelong getAndSetLong(long offsetBytes,
long newValue)
offsetBytes - offset bytes relative to this Memory startnewValue - new valueboolean getBoolean(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getBooleanArray(long offsetBytes,
boolean[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.byte getByte(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getByteArray(long offsetBytes,
byte[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.char getChar(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getCharArray(long offsetBytes,
char[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.double getDouble(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getDoubleArray(long offsetBytes,
double[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.float getFloat(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getFloatArray(long offsetBytes,
float[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.int getInt(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getIntArray(long offsetBytes,
int[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.long getLong(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getLongArray(long offsetBytes,
long[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.short getShort(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startvoid getShortArray(long offsetBytes,
short[] dstArray,
int dstOffset,
int length)
offsetBytes - offset bytes relative to this Memory startdstArray - The destination array.dstOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.boolean isAllBitsClear(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedboolean isAllBitsSet(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedboolean isAnyBitsClear(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedboolean isAnyBitsSet(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory startbitMask - bits set to one will be checkedvoid putBoolean(long offsetBytes,
boolean value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putBooleanArray(long offsetBytes,
boolean[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void putByte(long offsetBytes,
byte value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putByteArray(long offsetBytes,
byte[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void putChar(long offsetBytes,
char value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putCharArray(long offsetBytes,
char[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void putDouble(long offsetBytes,
double value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putDoubleArray(long offsetBytes,
double[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void putFloat(long offsetBytes,
float value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putFloatArray(long offsetBytes,
float[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void putInt(long offsetBytes,
int value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putIntArray(long offsetBytes,
int[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void putLong(long offsetBytes,
long value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putLongArray(long offsetBytes,
long[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void putShort(long offsetBytes,
short value)
offsetBytes - offset bytes relative to this Memory startvalue - the value to putvoid putShortArray(long offsetBytes,
short[] srcArray,
int srcOffset,
int length)
offsetBytes - offset bytes relative to this Memory startsrcArray - The source array.srcOffset - offset in array unitslength - number of array units to transfer
The size of this array determines the bytes transferred.void setBits(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory startbitMask - the bits set to one will be setObject array()
Memory asReadOnlyMemory()
ByteBuffer byteBuffer()
long getAddress(long offsetBytes)
Note that the precise definition of the returned address is slightly different for
NativeMemory.getAddress(long) as it is the root of the Memory hierarchy and has no
parent.
offsetBytes - the given offset in bytes from the start address of this Memory
relative to its parent.NativeMemory.getAddress(long)long getCapacity()
long getCumulativeOffset(long offsetBytes)
offsetBytes - the given offset in bytesMemoryRequest getMemoryRequest()
NativeMemory getNativeMemory()
Object getParent()
boolean hasArray()
boolean hasByteBuffer()
boolean isAllocated()
boolean isDirect()
boolean isReadOnly()
void setMemoryRequest(MemoryRequest memReq)
memReq - the MemoryRequestString toHexString(String header, long offsetBytes, int lengthBytes)
header - decriptive headeroffsetBytes - offset bytes relative to this Memory startlengthBytes - number of bytes to convert to a hex stringCopyright © 2015–2016 Yahoo! Inc.. All rights reserved.