@Internal public final class HybridMemorySegment extends MemorySegment
This class specialized byte access and byte copy calls for heap memory, while reusing the multi-byte type accesses and cross-segment operations from the MemorySegment.
This class subsumes the functionality of the HeapMemorySegment
,
but is a bit less efficient for operations on individual bytes.
Note that memory segments should usually not be allocated manually, but rather through the
MemorySegmentFactory
.
Modifier and Type | Class and Description |
---|---|
static class |
HybridMemorySegment.HybridMemorySegmentFactory
Base factory for hybrid memory segments.
|
Modifier and Type | Field and Description |
---|---|
static HybridMemorySegment.HybridMemorySegmentFactory |
FACTORY |
address, addressLimit, BYTE_ARRAY_BASE_OFFSET, heapMemory, size, UNSAFE
Modifier and Type | Method and Description |
---|---|
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() |
boolean |
getBoolean(int index)
Reads one byte at the given position and returns its boolean
representation.
|
ByteBuffer |
getOffHeapBuffer()
Gets the buffer that owns the memory of this memory segment.
|
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, free, 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, swapBytes
public static final HybridMemorySegment.HybridMemorySegmentFactory FACTORY
public byte[] getArray()
public ByteBuffer getOffHeapBuffer()
public ByteBuffer wrap(int offset, int length)
MemorySegment
wrap
in class MemorySegment
offset
- The offset in the memory segment.length
- The number of bytes to be wrapped as a buffer.public byte get(int index)
MemorySegment
get
in class MemorySegment
index
- The position from which the byte will be readpublic void put(int index, byte b)
MemorySegment
put
in class MemorySegment
index
- The index at which the byte will be written.b
- The byte value to be written.public void get(int index, byte[] dst)
MemorySegment
get
in class MemorySegment
index
- The position at which the first byte will be read.dst
- The memory into which the memory will be copied.public void put(int index, byte[] src)
MemorySegment
put
in class MemorySegment
index
- The index in the memory segment array, where the data is put.src
- The source array to copy the data from.public void get(int index, byte[] dst, int offset, int length)
MemorySegment
get
in class MemorySegment
index
- 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 void put(int index, byte[] src, int offset, int length)
MemorySegment
put
in class MemorySegment
index
- 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 boolean getBoolean(int index)
MemorySegment
getBoolean
in class MemorySegment
index
- The position from which the memory will be read.public void putBoolean(int index, boolean value)
MemorySegment
putBoolean
in class MemorySegment
index
- 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 MemorySegment
IOException
public final void put(DataInput in, int offset, int length) throws IOException
MemorySegment
put
in class MemorySegment
in
- 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)
MemorySegment
numBytes
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 MemorySegment
offset
- 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)
MemorySegment
numBytes
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 MemorySegment
offset
- 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–2017 The Apache Software Foundation. All rights reserved.