public abstract class WritableMemory extends Memory
| Modifier and Type | Method and Description |
|---|---|
static WritableMemory |
allocate(int capacityBytes)
Creates on-heap WritableMemory with the given capacity and the native byte order.
|
static WritableMemory |
allocate(int capacityBytes,
ByteOrder byteOrder)
Creates on-heap WritableMemory with the given capacity and the given byte order.
|
static WritableDirectHandle |
allocateDirect(long capacityBytes)
Allocates and provides access to capacityBytes directly in native (off-heap) memory
leveraging the WritableMemory API.
|
static WritableDirectHandle |
allocateDirect(long capacityBytes,
MemoryRequestServer memReqSvr)
Allocates and provides access to capacityBytes directly in native (off-heap) memory
leveraging the WritableMemory API.
|
abstract WritableBuffer |
asWritableBuffer()
Returns a new WritableBuffer with a writable view of this object.
|
abstract WritableBuffer |
asWritableBuffer(ByteOrder byteOrder)
Returns a new WritableBuffer with a writable view of this object
with the given byte order.
|
void |
checkValidAndBounds(long offsetBytes,
long lengthBytes)
Checks that the specified range of bytes is within bounds of this object, throws
IllegalArgumentException if it's not: i. |
abstract void |
clear()
Clears all bytes of this Memory to zero
|
abstract void |
clear(long offsetBytes,
long lengthBytes)
Clears a portion of this Memory to zero.
|
abstract void |
clearBits(long offsetBytes,
byte bitMask)
Clears the bits defined by the bitMask
|
abstract 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. |
boolean |
equals(Object that)
Returns true if the given object is an instance of this class and has equal data contents.
|
boolean |
equalTo(long thisOffsetBytes,
Object that,
long thatOffsetBytes,
long lengthBytes)
Returns true if the given object is an instance of this class and has equal contents to
this object in the given range of bytes.
|
abstract void |
fill(byte value)
Fills all bytes of this Memory region to the given byte value.
|
abstract void |
fill(long offsetBytes,
long lengthBytes,
byte value)
Fills a portion of this Memory region to the given byte value.
|
abstract long |
getAndAddLong(long offsetBytes,
long delta)
Atomically adds the given value to the long located at offsetBytes.
|
abstract long |
getAndSetLong(long offsetBytes,
long newValue)
Atomically exchanges the given value with the current value located at offsetBytes.
|
abstract Object |
getArray()
Returns the primitive backing array, otherwise null.
|
ByteBuffer |
getByteBuffer()
Gets the backing ByteBuffer if it exists, otherwise returns null.
|
ByteOrder |
getByteOrder()
Gets the current ByteOrder.
|
long |
getCapacity()
Gets the capacity of this object in bytes
|
long |
getCumulativeOffset()
Gets the cumulative offset in bytes of this object from the backing resource.
|
long |
getCumulativeOffset(long offsetBytes)
Gets the cumulative offset in bytes of this object from the backing resource including the given
offsetBytes.
|
static long |
getCurrentDirectMemoryAllocated()
Gets the current size of active direct memory allocated.
|
static long |
getCurrentDirectMemoryAllocations()
Gets the current number of active direct memory allocations.
|
static long |
getCurrentDirectMemoryMapAllocated()
Gets the current size of active direct memory map allocated.
|
static long |
getCurrentDirectMemoryMapAllocations()
Gets the current number of active direct memory map allocations.
|
MemoryRequestServer |
getMemoryRequestServer()
For Direct Memory only.
|
long |
getRegionOffset()
Returns the offset of address zero of this object relative to the address zero of the
backing resource but not including the size of any Java object header.
|
long |
getRegionOffset(long offsetBytes)
Returns the offset of address zero of this object relative to the address zero of the
backing resource plus the given offsetBytes but not including the size of any Java object
header.
|
boolean |
hasArray()
Returns true if this object is backed by an on-heap primitive array
|
boolean |
hasByteBuffer()
Returns true if this Memory is backed by a ByteBuffer.
|
int |
hashCode()
Returns the hashCode of this object.
|
boolean |
isDirect()
Returns true if the backing resource is direct (off-heap) memory.
|
boolean |
isNativeOrder()
Returns true if the current byte order is native order.
|
boolean |
isReadOnly()
Returns true if this object or the backing resource is read-only.
|
boolean |
isSameResource(Object that)
Returns true if the backing resource of this is identical with the backing resource
of that.
|
boolean |
isValid()
Returns true if this object is valid and has not been closed.
|
static WritableMapHandle |
map(File file)
Maps the entire given file into native-ordered Memory for write operations
(including those > 2GB).
|
static WritableMapHandle |
map(File file,
long fileOffsetBytes,
long capacityBytes,
ByteOrder byteOrder)
Maps the specified portion of the given file into Memory for write operations
(including those > 2GB).
|
abstract void |
putBoolean(long offsetBytes,
boolean value)
Puts the boolean value at the given offset
|
abstract void |
putBooleanArray(long offsetBytes,
boolean[] srcArray,
int srcOffsetBooleans,
int lengthBooleans)
Puts the boolean array at the given offset
|
abstract void |
putByte(long offsetBytes,
byte value)
Puts the byte value at the given offset
|
abstract void |
putByteArray(long offsetBytes,
byte[] srcArray,
int srcOffsetBytes,
int lengthBytes)
Puts the byte array at the given offset
|
abstract void |
putChar(long offsetBytes,
char value)
Puts the char value at the given offset
|
abstract void |
putCharArray(long offsetBytes,
char[] srcArray,
int srcOffsetChars,
int lengthChars)
Puts the char array at the given offset
|
abstract long |
putCharsToUtf8(long offsetBytes,
CharSequence src)
Encodes characters from the given CharSequence into UTF-8 bytes and puts them into this
WritableMemory begining at the given offsetBytes.
|
abstract void |
putDouble(long offsetBytes,
double value)
Puts the double value at the given offset
|
abstract void |
putDoubleArray(long offsetBytes,
double[] srcArray,
int srcOffsetDoubles,
int lengthDoubles)
Puts the double array at the given offset
|
abstract void |
putFloat(long offsetBytes,
float value)
Puts the float value at the given offset
|
abstract void |
putFloatArray(long offsetBytes,
float[] srcArray,
int srcOffsetFloats,
int lengthFloats)
Puts the float array at the given offset
|
abstract void |
putInt(long offsetBytes,
int value)
Puts the int value at the given offset
|
abstract void |
putIntArray(long offsetBytes,
int[] srcArray,
int srcOffsetInts,
int lengthInts)
Puts the int array at the given offset
|
abstract void |
putLong(long offsetBytes,
long value)
Puts the long value at the given offset
|
abstract void |
putLongArray(long offsetBytes,
long[] srcArray,
int srcOffsetLongs,
int lengthLongs)
Puts the long array at the given offset
|
abstract void |
putShort(long offsetBytes,
short value)
Puts the short value at the given offset
|
abstract void |
putShortArray(long offsetBytes,
short[] srcArray,
int srcOffsetShorts,
int lengthShorts)
Puts the short array at the given offset
|
abstract void |
setBits(long offsetBytes,
byte bitMask)
Sets the bits defined by the bitMask
|
String |
toHexString(String header,
long offsetBytes,
int lengthBytes)
Returns a formatted hex string of a range of this object.
|
static WritableMemory |
wrap(boolean[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
static WritableMemory |
wrap(byte[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
static WritableMemory |
wrap(byte[] arr,
ByteOrder byteOrder)
Wraps the given primitive array for write operations with the given byte order.
|
static WritableMemory |
wrap(byte[] arr,
int offsetBytes,
int lengthBytes,
ByteOrder byteOrder)
Wraps the given primitive array for write operations with the given byte order.
|
static WritableMemory |
wrap(ByteBuffer byteBuf)
Accesses the given ByteBuffer for write operations.
|
static WritableMemory |
wrap(ByteBuffer byteBuf,
ByteOrder byteOrder)
Accesses the given ByteBuffer for write operations.
|
static WritableMemory |
wrap(char[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
static WritableMemory |
wrap(double[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
static WritableMemory |
wrap(float[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
static WritableMemory |
wrap(int[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
static WritableMemory |
wrap(long[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
static WritableMemory |
wrap(short[] arr)
Wraps the given primitive array for write operations assuming native byte order.
|
abstract WritableMemory |
writableRegion(long offsetBytes,
long capacityBytes)
A writable region is a writable view of this object.
|
abstract WritableMemory |
writableRegion(long offsetBytes,
long capacityBytes,
ByteOrder byteOrder)
A writable region is a writable view of this object.
|
long |
xxHash64(long offsetBytes,
long lengthBytes,
long seed)
Returns the 64-bit hash of the sequence of bytes in this object specified by
offsetBytes, lengthBytes and a seed.
|
asBuffer, asBuffer, compareTo, copyTo, getBoolean, getBooleanArray, getByte, getByteArray, getChar, getCharArray, getCharsFromUtf8, getCharsFromUtf8, getDouble, getDoubleArray, getFloat, getFloatArray, getInt, getIntArray, getLong, getLongArray, getShort, getShortArray, region, region, unsafeByteBufferView, writeTopublic static WritableMemory wrap(ByteBuffer byteBuf)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
byteBuf - the given ByteBufferpublic static WritableMemory wrap(ByteBuffer byteBuf, ByteOrder byteOrder)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
byteBuf - the given ByteBuffer, must not be nullbyteOrder - the byte order to be used, which may be independent of the byte order
state of the given ByteBufferpublic static WritableMapHandle map(File file) throws IOException
map(file, 0, file.length(), ByteOrder.nativeOrder()).
Note: Always qualify this method with the class name, e.g., WritableMemory.map(...).
file - the given file to mapIOException - file not found or a RuntimeException.public static WritableMapHandle map(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) throws IOException
Note: Always qualify this method with the class name, e.g., WritableMemory.map(...).
file - the given file to map. It may not be null.fileOffsetBytes - the position in the given file in bytes. It may not be negative.capacityBytes - the size of the mapped Memory. It may not be negative or zero.byteOrder - the byte order to be used for the given file. It may not be null.IOException - file not found or RuntimeException, etc.public static WritableDirectHandle allocateDirect(long capacityBytes)
WritableHandle.get() are unspecified.
The default MemoryRequestServer, which allocates any request for memory onto the heap, will be used.
NOTE: Native/Direct memory acquired using Unsafe may have garbage in it. It is the responsibility of the using class to clear this memory, if required, and to call close() when done.
capacityBytes - the size of the desired memory in bytes.public static WritableDirectHandle allocateDirect(long capacityBytes, MemoryRequestServer memReqSvr)
WritableHandle.get() are unspecified.
NOTE: Native/Direct memory acquired using Unsafe may have garbage in it. It is the responsibility of the using class to clear this memory, if required, and to call close() when done.
capacityBytes - the size of the desired memory in bytes.memReqSvr - A user-specified MemoryRequestServer.
This is a callback mechanism for a user client of direct memory to request more memory.public abstract WritableMemory writableRegion(long offsetBytes, long capacityBytes)
offsetBytes - the starting offset with respect to this object.capacityBytes - the capacity of the returned object in bytes.public abstract WritableMemory writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder)
offsetBytes - the starting offset with respect to this object.capacityBytes - the capacity of the returned object in bytes.byteOrder - the given byte orderpublic abstract WritableBuffer asWritableBuffer()
public abstract WritableBuffer asWritableBuffer(ByteOrder byteOrder)
byteOrder - the given byte orderpublic static WritableMemory allocate(int capacityBytes)
capacityBytes - the given capacity in bytes.public static WritableMemory allocate(int capacityBytes, ByteOrder byteOrder)
capacityBytes - the given capacity in bytes.byteOrder - the given byte order to allocate new Memory object with.public static WritableMemory wrap(boolean[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public static WritableMemory wrap(byte[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public static WritableMemory wrap(byte[] arr, ByteOrder byteOrder)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.byteOrder - the byte order to be usedpublic static WritableMemory wrap(byte[] arr, int offsetBytes, int lengthBytes, ByteOrder byteOrder)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.offsetBytes - the byte offset into the given arraylengthBytes - the number of bytes to include from the given arraybyteOrder - the byte order to be usedpublic static WritableMemory wrap(char[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public static WritableMemory wrap(short[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public static WritableMemory wrap(int[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public static WritableMemory wrap(long[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public static WritableMemory wrap(float[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public static WritableMemory wrap(double[] arr)
Note: Always qualify this method with the class name, e.g., WritableMemory.wrap(...).
arr - the given primitive array.public abstract void putBoolean(long offsetBytes,
boolean value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putBooleanArray(long offsetBytes,
boolean[] srcArray,
int srcOffsetBooleans,
int lengthBooleans)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetBooleans - offset in array unitslengthBooleans - number of array units to transferpublic abstract void putByte(long offsetBytes,
byte value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putByteArray(long offsetBytes,
byte[] srcArray,
int srcOffsetBytes,
int lengthBytes)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetBytes - offset in array unitslengthBytes - number of array units to transferpublic abstract void putChar(long offsetBytes,
char value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putCharArray(long offsetBytes,
char[] srcArray,
int srcOffsetChars,
int lengthChars)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetChars - offset in array unitslengthChars - number of array units to transferpublic abstract long putCharsToUtf8(long offsetBytes,
CharSequence src)
offsetBytes - offset bytes relative to this WritableMemory startsrc - The source CharSequence to be encoded and put into this WritableMemory. It is
the responsibility of the caller to provide sufficient capacity in this
WritableMemory for the encoded Utf8 bytes. Characters outside the ASCII range can
require 2, 3 or 4 bytes per character to encode.public abstract void putDouble(long offsetBytes,
double value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putDoubleArray(long offsetBytes,
double[] srcArray,
int srcOffsetDoubles,
int lengthDoubles)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetDoubles - offset in array unitslengthDoubles - number of array units to transferpublic abstract void putFloat(long offsetBytes,
float value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putFloatArray(long offsetBytes,
float[] srcArray,
int srcOffsetFloats,
int lengthFloats)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetFloats - offset in array unitslengthFloats - number of array units to transferpublic abstract void putInt(long offsetBytes,
int value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putIntArray(long offsetBytes,
int[] srcArray,
int srcOffsetInts,
int lengthInts)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetInts - offset in array unitslengthInts - number of array units to transferpublic abstract void putLong(long offsetBytes,
long value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putLongArray(long offsetBytes,
long[] srcArray,
int srcOffsetLongs,
int lengthLongs)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetLongs - offset in array unitslengthLongs - number of array units to transferpublic abstract void putShort(long offsetBytes,
short value)
offsetBytes - offset bytes relative to this WritableMemory startvalue - the value to putpublic abstract void putShortArray(long offsetBytes,
short[] srcArray,
int srcOffsetShorts,
int lengthShorts)
offsetBytes - offset bytes relative to this WritableMemory startsrcArray - The source array.srcOffsetShorts - offset in array unitslengthShorts - number of array units to transferpublic abstract long getAndAddLong(long offsetBytes,
long delta)
offsetBytes - offset bytes relative to this Memory startdelta - the amount to addpublic abstract 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.public abstract long getAndSetLong(long offsetBytes,
long newValue)
offsetBytes - offset bytes relative to this Memory startnewValue - new valuepublic abstract Object getArray()
public abstract void clear()
public abstract void clear(long offsetBytes,
long lengthBytes)
offsetBytes - offset bytes relative to this Memory startlengthBytes - the length in bytespublic abstract void clearBits(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory start.bitMask - the bits set to one will be clearedpublic abstract void fill(byte value)
value - the given byte valuepublic abstract void fill(long offsetBytes,
long lengthBytes,
byte value)
offsetBytes - offset bytes relative to this Memory startlengthBytes - the length in bytesvalue - the given byte valuepublic abstract void setBits(long offsetBytes,
byte bitMask)
offsetBytes - offset bytes relative to this Memory startbitMask - the bits set to one will be setpublic MemoryRequestServer getMemoryRequestServer()
allocateDirect(long, MemoryRequestServer).
If not explicity set, this returns the DefaultMemoryRequestServer.public final boolean equals(Object that)
public final boolean equalTo(long thisOffsetBytes,
Object that,
long thatOffsetBytes,
long lengthBytes)
thisOffsetBytes - the starting offset in bytes for this object.that - the given objectthatOffsetBytes - the starting offset in bytes for the given objectlengthBytes - the size of the range in bytespublic ByteBuffer getByteBuffer()
public final ByteOrder getByteOrder()
public final long getCapacity()
public final long getCumulativeOffset()
public final long getCumulativeOffset(long offsetBytes)
offsetBytes - offset to be added to the cumulative offset.public final long getRegionOffset()
public final long getRegionOffset(long offsetBytes)
offsetBytes - the given offsetBytespublic final boolean hasArray()
public final int hashCode()
The hash code of this object depends upon all of its contents. Because of this, it is inadvisable to use these objects as keys in hash maps or similar data structures unless it is known that their contents will not change.
If it is desirable to use these objects in a hash map depending only on object identity,
than the IdentityHashMap can be used.
public final long xxHash64(long offsetBytes,
long lengthBytes,
long seed)
offsetBytes - the given offset in bytes to the first byte of the byte sequence.lengthBytes - the given length in bytes of the byte sequence.seed - the given long seed.public final boolean hasByteBuffer()
public final boolean isDirect()
public final boolean isNativeOrder()
public final boolean isReadOnly()
public final boolean isSameResource(Object that)
that - A different non-null objectpublic boolean isValid()
public final void checkValidAndBounds(long offsetBytes,
long lengthBytes)
IllegalArgumentException if it's not: i. e. if offsetBytes < 0, or length < 0,
or offsetBytes + length > getCapacity().offsetBytes - the given offset in bytes of this objectlengthBytes - the given length in bytes of this objectpublic static final long getCurrentDirectMemoryAllocations()
public static final long getCurrentDirectMemoryAllocated()
public static final long getCurrentDirectMemoryMapAllocations()
public static final long getCurrentDirectMemoryMapAllocated()
public final String toHexString(String header, long offsetBytes, int lengthBytes)
header - a descriptive headeroffsetBytes - offset bytes relative to this object startlengthBytes - number of bytes to convert to a hex stringCopyright © 2015–2018 Yahoo! Inc.. All rights reserved.