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 |
|---|---|
int |
addAndGetInt(long offsetBytes,
int delta)
Atomically adds the given value to the integer located at offsetBytes.
|
long |
addAndGetLong(long offsetBytes,
long delta)
Atomically adds the given value to the long located at offsetBytes.
|
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
|
boolean |
compareAndSwapInt(long offsetBytes,
int expect,
int update)
Atomically sets the current value at the memory location to the given updated value
if and only if the current value
== the expected value. |
boolean |
compareAndSwapLong(long offsetBytes,
long expect,
long update)
Atomically sets the current value at the memory location to the given updated value
if and only if the current value
== the expected value. |
void |
copy(long srcOffsetBytes,
long dstOffsetBytes,
long lengthBytes)
Deprecated.
Use
copy(long, Memory, long, long) instead. |
void |
copy(long srcOffsetBytes,
Memory destination,
long dstOffsetBytes,
long lengthBytes)
Copies bytes from a source range of this Memory to a destination range of the given Memory
using the same low-level system copy function as found in
System.arraycopy(Object, int, Object, int, int). |
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.
|
void |
freeMemory()
Because the Memory classes now use the JVM Cleaner, calling freeMemory(),
which also calls Cleaner, is optional.
|
long |
getAddress(long offsetBytes)
Returns the start address of this Memory relative to its parent plus the offset in bytes.
|
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 root of the Memory hierarchy
including the given offsetBytes.
|
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
|
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.
|
boolean 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transferbyte 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transferchar 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transferdouble 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transferfloat 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transferint 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transferlong 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transfershort 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 preallocated destination array.dstOffset - offset in array unitslength - number of array units to transferboolean 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 transfervoid 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 transfervoid 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 transfervoid 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 transfervoid 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 transfervoid 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 transfervoid 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 transfervoid 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 transfervoid setBits(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory startbitMask - the bits set to one will be setint addAndGetInt(long offsetBytes,
int delta)
offsetBytes - offset bytes relative to this Memory startdelta - the amount to addlong addAndGetLong(long offsetBytes,
long delta)
offsetBytes - offset bytes relative to this Memory startdelta - the amount to addboolean compareAndSwapInt(long offsetBytes,
int expect,
int update)
== the expected value.offsetBytes - offset bytes relative to this Memory startexpect - the expected valueupdate - the new valuetrue if successful. False return indicates that
the current value at the memory location was not equal to the expected value.boolean compareAndSwapLong(long offsetBytes,
long expect,
long update)
== the expected value.offsetBytes - offset bytes relative to this Memory startexpect - the expected valueupdate - the new valuetrue if successful. False return indicates that
the current value at the memory location was not equal to the expected value.int 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 valueObject array()
Memory asReadOnlyMemory()
ByteBuffer byteBuffer()
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 cleared@Deprecated void copy(long srcOffsetBytes, long dstOffsetBytes, long lengthBytes)
copy(long, Memory, long, long) instead.System.arraycopy(Object, int, Object, int, int).
These regions may not overlap. This will be checked if asserts are enabled in the JVM.srcOffsetBytes - the source offsetdstOffsetBytes - the destintaion offsetlengthBytes - the number of bytes to copyvoid copy(long srcOffsetBytes,
Memory destination,
long dstOffsetBytes,
long lengthBytes)
System.arraycopy(Object, int, Object, int, int).srcOffsetBytes - the source offset for this Memorydestination - the destination Memory, which may not be Read-Only.dstOffsetBytes - 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 valuelong getAddress(long offsetBytes)
offsetBytes - the given offset in bytes from the start address of this Memory
relative to its parent.long getCapacity()
long getCumulativeOffset(long offsetBytes)
offsetBytes - the given offset in bytesMemoryRequest getMemoryRequest()
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 - descriptive headeroffsetBytes - offset bytes relative to this Memory startlengthBytes - number of bytes to convert to a hex stringvoid freeMemory()
AllocMemory or MemoryMappedFile.
Preemptively calling freeMemory() may reduce the load on the JVM GarbageCollector, but the significance of this will have to be verified in the target system environment. Calling freeMemory() always disables the current instance by setting the capacity to zero.
Copyright © 2015–2017 Yahoo! Inc.. All rights reserved.