public abstract class Memory extends Object
com.yahoo.memory| Modifier and Type | Method and Description |
|---|---|
abstract Buffer |
asBuffer()
Returns a new Buffer view of this object.
|
abstract Buffer |
asBuffer(ByteOrder byteOrder)
Returns a new Buffer 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 int |
compareTo(long thisOffsetBytes,
long thisLengthBytes,
Memory that,
long thatOffsetBytes,
long thatLengthBytes)
Compares the bytes of this Memory to that Memory.
|
abstract void |
copyTo(long srcOffsetBytes,
WritableMemory destination,
long dstOffsetBytes,
long lengthBytes)
Copies bytes from a source range of this Memory to a destination range of the given Memory
with the same semantics when copying between overlapping ranges of bytes as method
System.arraycopy(Object, int, Object, int, int) has. |
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 boolean |
getBoolean(long offsetBytes)
Gets the boolean value at the given offset
|
abstract void |
getBooleanArray(long offsetBytes,
boolean[] dstArray,
int dstOffsetBooleans,
int lengthBooleans)
Gets the boolean array at the given offset
|
abstract byte |
getByte(long offsetBytes)
Gets the byte value at the given offset
|
abstract void |
getByteArray(long offsetBytes,
byte[] dstArray,
int dstOffsetBytes,
int lengthBytes)
Gets the byte array at the given offset
|
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
|
abstract char |
getChar(long offsetBytes)
Gets the char value at the given offset
|
abstract void |
getCharArray(long offsetBytes,
char[] dstArray,
int dstOffsetChars,
int lengthChars)
Gets the char array at the given offset
|
abstract int |
getCharsFromUtf8(long offsetBytes,
int utf8LengthBytes,
Appendable dst)
Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
utf8LengthBytes, decodes them into characters and appends them to the given Appendable.
|
abstract int |
getCharsFromUtf8(long offsetBytes,
int utf8LengthBytes,
StringBuilder dst)
Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
utf8LengthBytes, decodes them into characters and appends them to the given StringBuilder.
|
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.
|
abstract double |
getDouble(long offsetBytes)
Gets the double value at the given offset
|
abstract void |
getDoubleArray(long offsetBytes,
double[] dstArray,
int dstOffsetDoubles,
int lengthDoubles)
Gets the double array at the given offset
|
abstract float |
getFloat(long offsetBytes)
Gets the float value at the given offset
|
abstract void |
getFloatArray(long offsetBytes,
float[] dstArray,
int dstOffsetFloats,
int lengthFloats)
Gets the float array at the given offset
|
abstract int |
getInt(long offsetBytes)
Gets the int value at the given offset
|
abstract void |
getIntArray(long offsetBytes,
int[] dstArray,
int dstOffsetInts,
int lengthInts)
Gets the int array at the given offset
|
abstract long |
getLong(long offsetBytes)
Gets the long value at the given offset
|
abstract void |
getLongArray(long offsetBytes,
long[] dstArray,
int dstOffsetLongs,
int lengthLongs)
Gets the long array at the given offset
|
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.
|
abstract short |
getShort(long offsetBytes)
Gets the short value at the given offset
|
abstract void |
getShortArray(long offsetBytes,
short[] dstArray,
int dstOffsetShorts,
int lengthShorts)
Gets the short array at the given offset
|
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 MapHandle |
map(File file)
Maps the entire given file into native-ordered Memory for read operations
(including those > 2GB).
|
static MapHandle |
map(File file,
long fileOffsetBytes,
long capacityBytes,
ByteOrder byteOrder)
Maps the specified portion of the given file into Memory for read operations
(including those > 2GB).
|
abstract Memory |
region(long offsetBytes,
long capacityBytes)
A region is a read-only view of this object.
|
abstract Memory |
region(long offsetBytes,
long capacityBytes,
ByteOrder byteOrder)
A region is a read-only view of this object.
|
String |
toHexString(String header,
long offsetBytes,
int lengthBytes)
Returns a formatted hex string of a range of this object.
|
abstract ByteBuffer |
unsafeByteBufferView(long offsetBytes,
int capacityBytes)
Returns the specified region of this Memory object as a new read-only
ByteBuffer
object. |
static Memory |
wrap(boolean[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
static Memory |
wrap(byte[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
static Memory |
wrap(byte[] arr,
ByteOrder byteOrder)
Wraps the given primitive array for read operations with the given byte order.
|
static Memory |
wrap(byte[] arr,
int offsetBytes,
int lengthBytes,
ByteOrder byteOrder)
Wraps the given primitive array for read operations with the given byte order.
|
static Memory |
wrap(ByteBuffer byteBuf)
Accesses the given ByteBuffer for read-only operations.
|
static Memory |
wrap(ByteBuffer byteBuf,
ByteOrder byteOrder)
Accesses the given ByteBuffer for read-only operations.
|
static Memory |
wrap(char[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
static Memory |
wrap(double[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
static Memory |
wrap(float[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
static Memory |
wrap(int[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
static Memory |
wrap(long[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
static Memory |
wrap(short[] arr)
Wraps the given primitive array for read operations assuming native byte order.
|
abstract void |
writeTo(long offsetBytes,
long lengthBytes,
WritableByteChannel out)
Writes bytes from a source range of this Memory to the given
WritableByteChannel. |
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.
|
public static Memory wrap(ByteBuffer byteBuf)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
byteBuf - the given ByteBuffer, must not be nullpublic static Memory wrap(ByteBuffer byteBuf, ByteOrder byteOrder)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
byteBuf - the given ByteBuffer, must not be nullbyteOrder - the byte order to be used, whicn may be independent of the byte order
state of the given ByteBuffer.public static MapHandle map(File file) throws IOException
map(file, 0, file.length(), ByteOrder.nativeOrder()).
Note: Always qualify this method with the class name, e.g., Memory.map(...).
file - the given file to mapIOException - if file not found or a RuntimeException.public static MapHandle map(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) throws IOException
Note: Always qualify this method with the class name, e.g., Memory.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 mapped Memory. It may not be null.IOException - if file not found or a RuntimeException.public abstract Memory region(long offsetBytes, long capacityBytes)
offsetBytes - the starting offset with respect to the origin of this Memory.capacityBytes - the capacity of the region in bytespublic abstract Memory region(long offsetBytes, long capacityBytes, ByteOrder byteOrder)
offsetBytes - the starting offset with respect to the origin of this Memory.capacityBytes - the capacity of the region in bytesbyteOrder - the given byte orderpublic abstract Buffer asBuffer()
public abstract Buffer asBuffer(ByteOrder byteOrder)
byteOrder - the given byte orderpublic abstract ByteBuffer unsafeByteBufferView(long offsetBytes, int capacityBytes)
ByteBuffer
object. The ByteOrder of the returned ByteBuffer corresponds to the byte order of this Memory. The returned ByteBuffer's position is 0 and
the limit is equal to the capacity.
If this Memory object is the result of wrapping non-byte Java arrays (wrap(int[]), wrap(long[]), etc.) this methods throws an UnsupportedOperationException.
The name of this method starts with "unsafe" because if this is a native managed Memory
(e. g. obtained via map(File) or WritableMemory.allocateDirect(long))), and
the returned ByteBuffer object is used after the Memory is freed, it may cause a JVM
crash. This is also possible for Memory objects themselves with some methods,
but Memory's use-after-free is caught as an AssertionError, if assertions are enabled.
offsetBytes - the starting offset with respect to the origin of this MemorycapacityBytes - the capacity of the returned ByteBufferByteBuffer to access the specified region.UnsupportedOperationException - if this method couldn't be viewed as ByteBuffer, because
when it wraps a non-byte Java array.public static Memory wrap(boolean[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public static Memory wrap(byte[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public static Memory wrap(byte[] arr, ByteOrder byteOrder)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.byteOrder - the byte order to be usedpublic static Memory wrap(byte[] arr, int offsetBytes, int lengthBytes, ByteOrder byteOrder)
Note: Always qualify this method with the class name, e.g., Memory.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 Memory wrap(char[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public static Memory wrap(short[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public static Memory wrap(int[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public static Memory wrap(long[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public static Memory wrap(float[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public static Memory wrap(double[] arr)
Note: Always qualify this method with the class name, e.g., Memory.wrap(...).
arr - the given primitive array.public abstract boolean getBoolean(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getBooleanArray(long offsetBytes,
boolean[] dstArray,
int dstOffsetBooleans,
int lengthBooleans)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetBooleans - offset in array unitslengthBooleans - number of array units to transferpublic abstract byte getByte(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getByteArray(long offsetBytes,
byte[] dstArray,
int dstOffsetBytes,
int lengthBytes)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetBytes - offset in array unitslengthBytes - number of array units to transferpublic abstract char getChar(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getCharArray(long offsetBytes,
char[] dstArray,
int dstOffsetChars,
int lengthChars)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetChars - offset in array unitslengthChars - number of array units to transferpublic abstract int getCharsFromUtf8(long offsetBytes,
int utf8LengthBytes,
Appendable dst)
throws IOException,
Utf8CodingException
offsetBytes - offset bytes relative to the Memory startutf8LengthBytes - the number of encoded UTF-8 bytes to decode. It is assumed that the
caller has the correct number of utf8 bytes required to decode the number of characters
to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
character to decode.dst - the destination Appendable to append the decoded characters to.IOException - if dst.append() throws IOExceptionUtf8CodingException - in case of malformed or illegal UTF-8 inputpublic abstract int getCharsFromUtf8(long offsetBytes,
int utf8LengthBytes,
StringBuilder dst)
throws Utf8CodingException
offsetBytes - offset bytes relative to the Memory startutf8LengthBytes - the number of encoded UTF-8 bytes to decode. It is assumed that the
caller has the correct number of utf8 bytes required to decode the number of characters
to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
character to decode.dst - the destination StringBuilder to append decoded characters to.Utf8CodingException - in case of malformed or illegal UTF-8 inputpublic abstract double getDouble(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getDoubleArray(long offsetBytes,
double[] dstArray,
int dstOffsetDoubles,
int lengthDoubles)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetDoubles - offset in array unitslengthDoubles - number of array units to transferpublic abstract float getFloat(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getFloatArray(long offsetBytes,
float[] dstArray,
int dstOffsetFloats,
int lengthFloats)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetFloats - offset in array unitslengthFloats - number of array units to transferpublic abstract int getInt(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getIntArray(long offsetBytes,
int[] dstArray,
int dstOffsetInts,
int lengthInts)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetInts - offset in array unitslengthInts - number of array units to transferpublic abstract long getLong(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getLongArray(long offsetBytes,
long[] dstArray,
int dstOffsetLongs,
int lengthLongs)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetLongs - offset in array unitslengthLongs - number of array units to transferpublic abstract short getShort(long offsetBytes)
offsetBytes - offset bytes relative to this Memory startpublic abstract void getShortArray(long offsetBytes,
short[] dstArray,
int dstOffsetShorts,
int lengthShorts)
offsetBytes - offset bytes relative to this Memory startdstArray - The preallocated destination array.dstOffsetShorts - offset in array unitslengthShorts - number of array units to transferpublic abstract int compareTo(long thisOffsetBytes,
long thisLengthBytes,
Memory that,
long thatOffsetBytes,
long thatLengthBytes)
thisOffsetBytes - the starting offset for this MemorythisLengthBytes - the length of the region to compare from this Memorythat - the other Memory to compare withthatOffsetBytes - the starting offset for that MemorythatLengthBytes - the length of the region to compare from that Memorypublic abstract void copyTo(long srcOffsetBytes,
WritableMemory destination,
long dstOffsetBytes,
long lengthBytes)
System.arraycopy(Object, int, Object, int, int) has. However, if the source
and the destination ranges are exactly the same, this method throws IllegalArgumentException, because it should never be needed in real-world scenarios and
therefore indicates a bug.srcOffsetBytes - the source offset for this Memorydestination - the destination Memory, which may not be Read-Only.dstOffsetBytes - the destination offsetlengthBytes - the number of bytes to copypublic abstract void writeTo(long offsetBytes,
long lengthBytes,
WritableByteChannel out)
throws IOException
WritableByteChannel.offsetBytes - the source offset for this MemorylengthBytes - the number of bytes to copyout - the destination WritableByteChannelIOException - may occur while writing to the WritableByteChannelpublic 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.