@Internal public abstract class MemorySegment extends Object
The methods for individual memory access are specialized in the classes
HeapMemorySegment
and
HybridMemorySegment
.
All methods that operate across two memory segments are implemented in this class,
to transparently handle the mixing of memory segment types.
This class fulfills conceptually a similar purpose as Java's ByteBuffer
.
We add this specialized class for various reasons:
Below is an example of the code generated for the putLongBigEndian(int, long)
function by the just-in-time compiler. The code is grabbed from an Oracle JVM 7 using the
hotspot disassembler library (hsdis32.dll) and the jvm command
-XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MemorySegment.putLongBigEndian.
Note that this code realizes both the byte order swapping and the reinterpret cast access to
get a long from the byte array.
[Verified Entry Point] 0x00007fc403e19920: sub $0x18,%rsp 0x00007fc403e19927: mov %rbp,0x10(%rsp) ;*synchronization entry ; - org.apache.flink.runtime.memory.UnsafeMemorySegment::putLongBigEndian@-1 (line 652) 0x00007fc403e1992c: mov 0xc(%rsi),%r10d ;*getfield memory ; - org.apache.flink.runtime.memory.UnsafeMemorySegment::putLong@4 (line 611) ; - org.apache.flink.runtime.memory.UnsafeMemorySegment::putLongBigEndian@12 (line 653) 0x00007fc403e19930: bswap %rcx 0x00007fc403e19933: shl $0x3,%r10 0x00007fc403e19937: movslq %edx,%r11 0x00007fc403e1993a: mov %rcx,0x10(%r10,%r11,1) ;*invokevirtual putLong ; - org.apache.flink.runtime.memory.UnsafeMemorySegment::putLong@14 (line 611) ; - org.apache.flink.runtime.memory.UnsafeMemorySegment::putLongBigEndian@12 (line 653) 0x00007fc403e1993f: add $0x10,%rsp 0x00007fc403e19943: pop %rbp 0x00007fc403e19944: test %eax,0x5ba76b6(%rip) # 0x00007fc4099c1000 ; {poll_return} 0x00007fc403e1994a: retqNote on efficiency: For best efficiency, the code that uses this class should make sure that only one subclass is loaded, or that the methods that are abstract in this class are used only from one of the subclasses (either the
HeapMemorySegment
, or the
HybridMemorySegment
).
That way, all the abstract methods in the MemorySegment base class have only one loaded
actual implementation. This is easy for the JIT to recognize through class hierarchy analysis,
or by identifying that the invocations are monomorphic (all go to the same concrete
method implementation). Under these conditions, the JIT can perfectly inline methods.Modifier and Type | Field and Description |
---|---|
protected long |
address
The address to the data, relative to the heap memory byte array.
|
protected long |
addressLimit
The address one byte after the last addressable byte.
|
protected static long |
BYTE_ARRAY_BASE_OFFSET
The beginning of the byte array contents, relative to the byte array object
|
protected byte[] |
heapMemory
The heap byte array object relative to which we access the memory.
|
protected int |
size
The size in bytes of the memory segment
|
protected static sun.misc.Unsafe |
UNSAFE
The unsafe handle for transparent memory copied (heap / off-heap)
|
Modifier and Type | Method and Description |
---|---|
int |
compare(MemorySegment seg2,
int offset1,
int offset2,
int len)
Compares two memory segment regions.
|
void |
copyTo(int offset,
MemorySegment target,
int targetOffset,
int numBytes)
Bulk copy method.
|
void |
free()
Frees this memory segment.
|
abstract void |
get(DataOutput out,
int offset,
int length) |
abstract byte |
get(int index)
Reads the byte at the given position.
|
abstract void |
get(int index,
byte[] dst)
Bulk get method.
|
abstract void |
get(int index,
byte[] dst,
int offset,
int length)
Bulk get method.
|
abstract void |
get(int offset,
ByteBuffer target,
int numBytes)
Bulk get method.
|
abstract boolean |
getBoolean(int index)
Reads one byte at the given position and returns its boolean
representation.
|
char |
getChar(int index)
Reads a char value from the given position, in the system's native byte order.
|
char |
getCharBigEndian(int index)
Reads an character value (16 bit, 2 bytes) from the given position, in big-endian byte order.
|
char |
getCharLittleEndian(int index)
Reads an character value (16 bit, 2 bytes) from the given position, in little-endian byte order.
|
double |
getDouble(int index)
Reads a double-precision floating point value (64bit, 8 bytes) from the given position, in the system's
native byte order.
|
double |
getDoubleBigEndian(int index)
Reads a double-precision floating point value (64bit, 8 bytes) from the given position, in big endian
byte order.
|
double |
getDoubleLittleEndian(int index)
Reads a double-precision floating point value (64bit, 8 bytes) from the given position, in little endian
byte order.
|
float |
getFloat(int index)
Reads a single-precision floating point value (32bit, 4 bytes) from the given position, in the system's
native byte order.
|
float |
getFloatBigEndian(int index)
Reads a single-precision floating point value (32bit, 4 bytes) from the given position, in big endian
byte order.
|
float |
getFloatLittleEndian(int index)
Reads a single-precision floating point value (32bit, 4 bytes) from the given position, in little endian
byte order.
|
int |
getInt(int index)
Reads an int value (32bit, 4 bytes) from the given position, in the system's native byte order.
|
int |
getIntBigEndian(int index)
Reads an int value (32bit, 4 bytes) from the given position, in big-endian byte order.
|
int |
getIntLittleEndian(int index)
Reads an int value (32bit, 4 bytes) from the given position, in little-endian byte order.
|
long |
getLong(int index)
Reads a long value (64bit, 8 bytes) from the given position, in the system's native byte order.
|
long |
getLongBigEndian(int index)
Reads a long integer value (64bit, 8 bytes) from the given position, in big endian byte order.
|
long |
getLongLittleEndian(int index)
Reads a long integer value (64bit, 8 bytes) from the given position, in little endian byte order.
|
Object |
getOwner()
Gets the owner of this memory segment.
|
short |
getShort(int index)
Reads two memory at the given position, composing them into a short value
according to the current byte order.
|
short |
getShortBigEndian(int index)
Reads an short integer value (16 bit, 2 bytes) from the given position, in big-endian byte order.
|
short |
getShortLittleEndian(int index)
Reads an short integer value (16 bit, 2 bytes) from the given position, in little-endian byte order.
|
boolean |
isFreed()
Checks whether the memory segment was freed.
|
boolean |
isOffHeap()
Checks whether this memory segment is backed by off-heap memory.
|
abstract void |
put(DataInput in,
int offset,
int length)
Bulk put method.
|
abstract void |
put(int index,
byte b)
Writes the given byte into this buffer at the given position.
|
abstract void |
put(int index,
byte[] src)
Bulk put method.
|
abstract void |
put(int index,
byte[] src,
int offset,
int length)
Bulk put method.
|
abstract void |
put(int offset,
ByteBuffer source,
int numBytes)
Bulk put method.
|
abstract void |
putBoolean(int index,
boolean value)
Writes one byte containing the byte value into this buffer at the given
position.
|
void |
putChar(int index,
char value)
Writes a char value to teh given position, in the system's native byte order.
|
void |
putCharBigEndian(int index,
char value)
Writes the given character (16 bit, 2 bytes) to the given position in big-endian
byte order.
|
void |
putCharLittleEndian(int index,
char value)
Writes the given character (16 bit, 2 bytes) to the given position in little-endian
byte order.
|
void |
putDouble(int index,
double value)
Writes the given double-precision floating-point value (64bit, 8 bytes) to the given position in the
system's native byte order.
|
void |
putDoubleBigEndian(int index,
double value)
Writes the given double-precision floating-point value (64bit, 8 bytes) to the given position in big endian
byte order.
|
void |
putDoubleLittleEndian(int index,
double value)
Writes the given double-precision floating-point value (64bit, 8 bytes) to the given position in little endian
byte order.
|
void |
putFloat(int index,
float value)
Writes the given single-precision float value (32bit, 4 bytes) to the given position in the system's native
byte order.
|
void |
putFloatBigEndian(int index,
float value)
Writes the given single-precision float value (32bit, 4 bytes) to the given position in big endian
byte order.
|
void |
putFloatLittleEndian(int index,
float value)
Writes the given single-precision float value (32bit, 4 bytes) to the given position in little endian
byte order.
|
void |
putInt(int index,
int value)
Writes the given int value (32bit, 4 bytes) to the given position in the system's native
byte order.
|
void |
putIntBigEndian(int index,
int value)
Writes the given int value (32bit, 4 bytes) to the given position in big endian
byte order.
|
void |
putIntLittleEndian(int index,
int value)
Writes the given int value (32bit, 4 bytes) to the given position in little endian
byte order.
|
void |
putLong(int index,
long value)
Writes the given long value (64bit, 8 bytes) to the given position in the system's native
byte order.
|
void |
putLongBigEndian(int index,
long value)
Writes the given long value (64bit, 8 bytes) to the given position in big endian
byte order.
|
void |
putLongLittleEndian(int index,
long value)
Writes the given long value (64bit, 8 bytes) to the given position in little endian
byte order.
|
void |
putShort(int index,
short value)
Writes the given short value into this buffer at the given position, using
the native byte order of the system.
|
void |
putShortBigEndian(int index,
short value)
Writes the given short integer value (16 bit, 2 bytes) to the given position in big-endian
byte order.
|
void |
putShortLittleEndian(int index,
short value)
Writes the given short integer value (16 bit, 2 bytes) to the given position in little-endian
byte order.
|
int |
size()
Gets the size of the memory segment, in bytes.
|
void |
swapBytes(byte[] tempBuffer,
MemorySegment seg2,
int offset1,
int offset2,
int len)
Swaps bytes between two memory segments, using the given auxiliary buffer.
|
abstract ByteBuffer |
wrap(int offset,
int length)
Wraps the chunk of the underlying memory located between offset and
length in a NIO ByteBuffer.
|
protected static final sun.misc.Unsafe UNSAFE
protected static final long BYTE_ARRAY_BASE_OFFSET
protected final byte[] heapMemory
protected long address
protected final long addressLimit
protected final int size
public int size()
public boolean isFreed()
public void free()
public boolean isOffHeap()
public abstract ByteBuffer wrap(int offset, int length)
offset
- The offset in the memory segment.length
- The number of bytes to be wrapped as a buffer.IndexOutOfBoundsException
- Thrown, if offset is negative or larger than the memory segment size,
or if the offset plus the length is larger than the segment size.public Object getOwner()
public abstract byte get(int index)
index
- The position from which the byte will be readIndexOutOfBoundsException
- Thrown, if the index is negative, or larger or equal to the size of
the memory segment.public abstract void put(int index, byte b)
index
- The index at which the byte will be written.b
- The byte value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger or equal to the size of
the memory segment.public abstract void get(int index, byte[] dst)
index
- The position at which the first byte will be read.dst
- The memory into which the memory will be copied.IndexOutOfBoundsException
- Thrown, if the index is negative, or too large that the data between the
index and the memory segment end is not enough to fill the destination array.public abstract void put(int index, byte[] src)
index
- The index in the memory segment array, where the data is put.src
- The source array to copy the data from.IndexOutOfBoundsException
- Thrown, if the index is negative, or too large such that the array
size exceed the amount of memory between the index and the memory
segment's end.public abstract void get(int index, byte[] dst, int offset, int length)
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.IndexOutOfBoundsException
- Thrown, if the index is negative, or too large that the requested number of
bytes exceed the amount of memory between the index and the memory
segment's end.public abstract void put(int index, byte[] src, int offset, int length)
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.IndexOutOfBoundsException
- Thrown, if the index is negative, or too large such that the array
portion to copy exceed the amount of memory between the index and the memory
segment's end.public abstract boolean getBoolean(int index)
index
- The position from which the memory will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 1.public abstract void putBoolean(int index, boolean value)
index
- The position at which the memory will be written.value
- The char value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 1.public final char getChar(int index)
index
- The position from which the memory will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 2.public final char getCharLittleEndian(int index)
getChar(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getChar(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final char getCharBigEndian(int index)
getChar(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getChar(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final void putChar(int index, char value)
index
- The position at which the memory will be written.value
- The char value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 2.public final void putCharLittleEndian(int index, char value)
putChar(int, char)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putChar(int, char)
is the preferable choice.index
- The position at which the value will be written.value
- The short value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final void putCharBigEndian(int index, char value)
putChar(int, char)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putChar(int, char)
is the preferable choice.index
- The position at which the value will be written.value
- The short value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final short getShort(int index)
index
- The position from which the memory will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 2.public final short getShortLittleEndian(int index)
getShort(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getShort(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final short getShortBigEndian(int index)
getShort(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getShort(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final void putShort(int index, short value)
index
- The position at which the value will be written.value
- The short value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 2.public final void putShortLittleEndian(int index, short value)
putShort(int, short)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putShort(int, short)
is the preferable choice.index
- The position at which the value will be written.value
- The short value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final void putShortBigEndian(int index, short value)
putShort(int, short)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putShort(int, short)
is the preferable choice.index
- The position at which the value will be written.value
- The short value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment size minus 2.public final int getInt(int index)
index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final int getIntLittleEndian(int index)
getInt(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getInt(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final int getIntBigEndian(int index)
getInt(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getInt(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final void putInt(int index, int value)
index
- The position at which the value will be written.value
- The int value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final void putIntLittleEndian(int index, int value)
putInt(int, int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putInt(int, int)
is the preferable choice.index
- The position at which the value will be written.value
- The int value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final void putIntBigEndian(int index, int value)
putInt(int, int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putInt(int, int)
is the preferable choice.index
- The position at which the value will be written.value
- The int value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final long getLong(int index)
index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final long getLongLittleEndian(int index)
getLong(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getLong(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final long getLongBigEndian(int index)
getLong(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getLong(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putLong(int index, long value)
index
- The position at which the value will be written.value
- The long value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putLongLittleEndian(int index, long value)
putLong(int, long)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putLong(int, long)
is the preferable choice.index
- The position at which the value will be written.value
- The long value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putLongBigEndian(int index, long value)
putLong(int, long)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putLong(int, long)
is the preferable choice.index
- The position at which the value will be written.value
- The long value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final float getFloat(int index)
index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final float getFloatLittleEndian(int index)
getFloat(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getFloat(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final float getFloatBigEndian(int index)
getFloat(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getFloat(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putFloat(int index, float value)
index
- The position at which the value will be written.value
- The float value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 4.public final void putFloatLittleEndian(int index, float value)
putFloat(int, float)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putFloat(int, float)
is the preferable choice.index
- The position at which the value will be written.value
- The long value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putFloatBigEndian(int index, float value)
putFloat(int, float)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putFloat(int, float)
is the preferable choice.index
- The position at which the value will be written.value
- The long value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final double getDouble(int index)
index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final double getDoubleLittleEndian(int index)
getDouble(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getDouble(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final double getDoubleBigEndian(int index)
getDouble(int)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and getDouble(int)
is the preferable choice.index
- The position from which the value will be read.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putDouble(int index, double value)
index
- The position at which the memory will be written.value
- The double value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putDoubleLittleEndian(int index, double value)
putDouble(int, double)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putDouble(int, double)
is the preferable choice.index
- The position at which the value will be written.value
- The long value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public final void putDoubleBigEndian(int index, double value)
putDouble(int, double)
. For most cases (such as
transient storage in memory or serialization for I/O and network),
it suffices to know that the byte order in which the value is written is the same as the
one in which it is read, and putDouble(int, double)
is the preferable choice.index
- The position at which the value will be written.value
- The long value to be written.IndexOutOfBoundsException
- Thrown, if the index is negative, or larger then the segment
size minus 8.public abstract void get(DataOutput out, int offset, int length) throws IOException
IOException
public abstract void put(DataInput in, int offset, int length) throws IOException
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 abstract void get(int offset, ByteBuffer target, int numBytes)
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
.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.IndexOutOfBoundsException
- If the offset is invalid, or this segment does not
contain the given number of bytes (starting from offset), or the target byte buffer does
not have enough space for the bytes.public abstract void put(int offset, ByteBuffer source, int numBytes)
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
.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.IndexOutOfBoundsException
- If the offset is invalid, or the source buffer does not
contain the given number of bytes, or this segment does
not have enough space for the bytes (counting from offset).public final void copyTo(int offset, MemorySegment target, int targetOffset, int numBytes)
numBytes
bytes from this memory segment, starting at position
offset
to the target memory segment. The bytes will be put into the target segment
starting at position targetOffset
.offset
- The position where the bytes are started to be read from in this memory segment.target
- The memory segment to copy the bytes to.targetOffset
- The position in the target memory segment to copy the chunk to.numBytes
- The number of bytes to copy.IndexOutOfBoundsException
- If either of the offsets is invalid, or the source segment does not
contain the given number of bytes (starting from offset), or the target segment does
not have enough space for the bytes (counting from targetOffset).public final int compare(MemorySegment seg2, int offset1, int offset2, int len)
seg2
- Segment to compare this segment withoffset1
- Offset of this segment to start comparingoffset2
- Offset of seg2 to start comparinglen
- Length of the compared memory regionpublic final void swapBytes(byte[] tempBuffer, MemorySegment seg2, int offset1, int offset2, int len)
tempBuffer
- The auxiliary buffer in which to put data during triangle swap.seg2
- Segment to swap bytes withoffset1
- Offset of this segment to start swappingoffset2
- Offset of seg2 to start swappinglen
- Length of the swapped memory regionCopyright © 2014–2017 The Apache Software Foundation. All rights reserved.