@Internal public final class HeapMemorySegment extends MemorySegment
This class specializes byte access and byte copy calls for heap memory, while reusing the multi-byte type accesses and cross-segment operations from the MemorySegment.
Note that memory segments should usually not be allocated manually, but rather through the
MemorySegmentFactory.
| Modifier and Type | Class and Description |
|---|---|
static class |
HeapMemorySegment.HeapMemorySegmentFactory
A memory segment factory that produces heap memory segments.
|
| Modifier and Type | Field and Description |
|---|---|
static HeapMemorySegment.HeapMemorySegmentFactory |
FACTORY |
address, addressLimit, BYTE_ARRAY_BASE_OFFSET, heapMemory, size, UNSAFE| Modifier and Type | Method and Description |
|---|---|
void |
free()
Frees this memory segment.
|
void |
get(DataOutput out,
int offset,
int length) |
byte |
get(int index)
Reads the byte at the given position.
|
void |
get(int index,
byte[] dst)
Bulk get method.
|
void |
get(int index,
byte[] dst,
int offset,
int length)
Bulk get method.
|
void |
get(int offset,
ByteBuffer target,
int numBytes)
Bulk get method.
|
byte[] |
getArray()
Gets the byte array that backs this memory segment.
|
boolean |
getBoolean(int index)
Reads one byte at the given position and returns its boolean
representation.
|
void |
put(DataInput in,
int offset,
int length)
Bulk put method.
|
void |
put(int index,
byte b)
Writes the given byte into this buffer at the given position.
|
void |
put(int index,
byte[] src)
Bulk put method.
|
void |
put(int index,
byte[] src,
int offset,
int length)
Bulk put method.
|
void |
put(int offset,
ByteBuffer source,
int numBytes)
Bulk put method.
|
void |
putBoolean(int index,
boolean value)
Writes one byte containing the byte value into this buffer at the given
position.
|
ByteBuffer |
wrap(int offset,
int length)
Wraps the chunk of the underlying memory located between offset and
length in a NIO ByteBuffer.
|
compare, copyTo, getAddress, getChar, getCharBigEndian, getCharLittleEndian, getDouble, getDoubleBigEndian, getDoubleLittleEndian, getFloat, getFloatBigEndian, getFloatLittleEndian, getInt, getIntBigEndian, getIntLittleEndian, getLong, getLongBigEndian, getLongLittleEndian, getOwner, getShort, getShortBigEndian, getShortLittleEndian, isFreed, isOffHeap, putChar, putCharBigEndian, putCharLittleEndian, putDouble, putDoubleBigEndian, putDoubleLittleEndian, putFloat, putFloatBigEndian, putFloatLittleEndian, putInt, putIntBigEndian, putIntLittleEndian, putLong, putLongBigEndian, putLongLittleEndian, putShort, putShortBigEndian, putShortLittleEndian, size, swapBytespublic static final HeapMemorySegment.HeapMemorySegmentFactory FACTORY
public void free()
MemorySegmentAfter this operation has been called, no further operations are possible on the memory segment and will fail. The actual memory (heap or off-heap) will only be released after this memory segment object has become garbage collected.
free in class MemorySegmentpublic ByteBuffer wrap(int offset, int length)
MemorySegmentwrap in class MemorySegmentoffset - The offset in the memory segment.length - The number of bytes to be wrapped as a buffer.public byte[] getArray()
getArray in class MemorySegmentpublic final byte get(int index)
MemorySegmentget in class MemorySegmentindex - The position from which the byte will be readpublic final void put(int index,
byte b)
MemorySegmentput in class MemorySegmentindex - The index at which the byte will be written.b - The byte value to be written.public final void get(int index,
byte[] dst)
MemorySegmentget in class MemorySegmentindex - The position at which the first byte will be read.dst - The memory into which the memory will be copied.public final void put(int index,
byte[] src)
MemorySegmentput in class MemorySegmentindex - The index in the memory segment array, where the data is put.src - The source array to copy the data from.public final void get(int index,
byte[] dst,
int offset,
int length)
MemorySegmentget in class MemorySegmentindex - The position at which the first byte will be read.dst - The memory into which the memory will be copied.offset - The copying offset in the destination memory.length - The number of bytes to be copied.public final void put(int index,
byte[] src,
int offset,
int length)
MemorySegmentput in class MemorySegmentindex - The position in the memory segment array, where the data is put.src - The source array to copy the data from.offset - The offset in the source array where the copying is started.length - The number of bytes to copy.public final boolean getBoolean(int index)
MemorySegmentgetBoolean in class MemorySegmentindex - The position from which the memory will be read.public final void putBoolean(int index,
boolean value)
MemorySegmentputBoolean in class MemorySegmentindex - The position at which the memory will be written.value - The char value to be written.public final void get(DataOutput out, int offset, int length) throws IOException
get in class MemorySegmentIOExceptionpublic final void put(DataInput in, int offset, int length) throws IOException
MemorySegmentput in class MemorySegmentin - The DataInput to get the data from.offset - The position in the memory segment to copy the chunk to.length - The number of bytes to get.IOException - Thrown, if the DataInput encountered a problem upon reading,
such as an End-Of-File.public final void get(int offset,
ByteBuffer target,
int numBytes)
MemorySegmentnumBytes bytes from this memory segment, starting at position
offset to the target ByteBuffer. The bytes will be put into the target buffer
starting at the buffer's current position. If this method attempts to write more bytes than
the target byte buffer has remaining (with respect to Buffer.remaining()),
this method will cause a BufferOverflowException.get in class MemorySegmentoffset - The position where the bytes are started to be read from in this memory segment.target - The ByteBuffer to copy the bytes to.numBytes - The number of bytes to copy.public final void put(int offset,
ByteBuffer source,
int numBytes)
MemorySegmentnumBytes bytes from the given ByteBuffer, into
this memory segment. The bytes will be read from the target buffer
starting at the buffer's current position, and will be written to this memory segment starting
at offset.
If this method attempts to read more bytes than
the target byte buffer has remaining (with respect to Buffer.remaining()),
this method will cause a BufferUnderflowException.put in class MemorySegmentoffset - The position where the bytes are started to be written to in this memory segment.source - The ByteBuffer to copy the bytes from.numBytes - The number of bytes to copy.Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.