MemorySegment (Java SE 22 & JDK 22)
-
Nested Class Summary
Nested Classes
static interfaceA scope models the lifetime of all the memory segments associated with it.
-
Field Summary
Fields
A zero-length native segment modelling the
NULLaddress. -
Method Summary
longaddress()Returns the address of this memory segment.
Returns a slice of this segment that is the overlap between this and the provided segment.
Returns a read-only view of this segment.
asSlice(long offset) Returns a slice of this memory segment, at the given offset.
asSlice(long offset, long newSize) Returns a slice of this memory segment, at the given offset.
asSlice(long offset, long newSize, long byteAlignment) Returns a slice of this memory segment, at the given offset, with the provided alignment constraint.
Returns a slice of this memory segment with the given layout, at the given offset.
longbyteSize()Returns the size (in bytes) of this memory segment.
static voidPerforms a bulk copy from source segment to destination segment.
static voidPerforms a bulk copy from source segment to destination segment.
static voidCopies a number of elements from a source memory segment to a destination array.
static voidCopies a number of elements from a source array to a destination memory segment.
Performs a bulk copy from the given source segment to this segment.
Returns a sequential
Streamover disjoint slices (whose size matches that of the specified layout) in this segment.booleanCompares the specified object with this memory segment for equality.
fill(byte value) Fills the contents of this memory segment with the given value.
voidforce()Forces any changes made to the contents of this mapped segment to be written to the storage device described by the mapped segment's file descriptor.
Reads an address from this segment at the given offset, with the given layout.
booleanReads a boolean from this segment at the given offset, with the given layout.
byteReads a byte from this segment at the given offset, with the given layout.
charReads a char from this segment at the given offset, with the given layout.
doubleReads a double from this segment at the given offset, with the given layout.
floatReads a float from this segment at the given offset, with the given layout.
intReads an int from this segment at the given offset, with the given layout.
longReads a long from this segment at the given offset, with the given layout.
shortReads a short from this segment at the given offset, with the given layout.
Reads an address from this segment at the given at the given index, scaled by the given layout size.
booleanReads a boolean from this segment at the given index, scaled by the given layout size.
byteReads a byte from this segment at the given index, scaled by the given layout size.
charReads a char from this segment at the given index, scaled by the given layout size.
doubleReads a double from this segment at the given index, scaled by the given layout size.
floatReads a float from this segment at the given index, scaled by the given layout size.
intReads an int from this segment at the given index, scaled by the given layout size.
longReads a long from this segment at the given index, scaled by the given layout size.
shortReads a short from this segment at the given index, scaled by the given layout size.
getString(long offset) Reads a null-terminated string from this segment at the given offset, using the UTF-8 charset.
getString(long offset, Charset charset) Reads a null-terminated string from this segment at the given offset, using the provided charset.
inthashCode()Returns the hash code value for this memory segment.
heapBase()Returns the Java object stored in the on-heap region of memory backing this memory segment, if any.
booleanReturns
trueif this segment can be accessed from the provided thread.booleanisLoaded()Determines whether all the contents of this mapped segment are resident in physical memory.
booleanisMapped()Returns
trueif this segment is a mapped segment.booleanisNative()Returns
trueif this segment is a native segment.booleanReturns
true, if this segment is read-only.voidload()Loads the contents of this mapped segment into physical memory.
longFinds and returns the offset, in bytes, of the first mismatch between this segment and the given other segment.
static longmismatch(MemorySegment srcSegment, long srcFromOffset, long srcToOffset, MemorySegment dstSegment, long dstFromOffset, long dstToOffset) Finds and returns the relative offset, in bytes, of the first mismatch between the source and the destination segments.
ofAddress(long address) Creates a zero-length native segment from the given address value.
ofArray(byte[] byteArray) Creates a heap segment backed by the on-heap region of memory that holds the given byte array.
ofArray(char[] charArray) Creates a heap segment backed by the on-heap region of memory that holds the given char array.
ofArray(double[] doubleArray) Creates a heap segment backed by the on-heap region of memory that holds the given double array.
ofArray(float[] floatArray) Creates a heap segment backed by the on-heap region of memory that holds the given float array.
ofArray(int[] intArray) Creates a heap segment backed by the on-heap region of memory that holds the given int array.
ofArray(long[] longArray) Creates a heap segment backed by the on-heap region of memory that holds the given long array.
ofArray(short[] shortArray) Creates a heap segment backed by the on-heap region of memory that holds the given short array.
Creates a memory segment that is backed by the same region of memory that backs the given
Bufferinstance.reinterpret(long newSize) Restricted.
Returns a new memory segment that has the same address and scope as this segment, but with the provided size.
Restricted.
Returns a new segment with the same address as this segment, but with the provided size and scope.
Restricted.
Returns a new memory segment with the same address and size as this segment, but with the provided scope.
scope()Returns the scope associated with this memory segment.
voidWrites an address into this segment at the given offset, with the given layout.
voidWrites a boolean into this segment at the given offset, with the given layout.
voidWrites a byte into this segment at the given offset, with the given layout.
voidWrites a char into this segment at the given offset, with the given layout.
voidWrites a double into this segment at the given offset, with the given layout.
voidWrites a float into this segment at the given offset, with the given layout.
voidWrites an int into this segment at the given offset, with the given layout.
voidWrites a long into this segment at the given offset, with the given layout.
voidWrites a short into this segment at the given offset, with the given layout.
voidWrites an address into this segment at the given index, scaled by the given layout size.
voidWrites a boolean into this segment at the given index, scaled by the given layout size.
voidWrites a byte into this segment at the given index, scaled by the given layout size.
voidWrites a char into this segment at the given index, scaled by the given layout size.
voidWrites a double into this segment at the given index, scaled by the given layout size.
voidWrites a float into this segment at the given index, scaled by the given layout size.
voidWrites an int into this segment at the given index, scaled by the given layout size.
voidWrites a long into this segment at the given index, scaled by the given layout size.
voidWrites a short into this segment at the given index, scaled by the given layout size.
voidWrites the given string into this segment at the given offset, converting it to a null-terminated byte sequence using the UTF-8 charset.
voidWrites the given string into this segment at the given offset, converting it to a null-terminated byte sequence using the provided charset.
Returns a spliterator for this memory segment.
byte[]Copy the contents of this memory segment into a new byte array.
char[]Copy the contents of this memory segment into a new char array.
double[]Copy the contents of this memory segment into a new double array.
float[]Copy the contents of this memory segment into a new float array.
int[]Copy the contents of this memory segment into a new int array.
long[]Copy the contents of this memory segment into a new long array.
short[]Copy the contents of this memory segment into a new short array.
voidunload()Unloads the contents of this mapped segment from physical memory.
-
Field Details
-
NULL
-
-
Method Details
-
address
-
heapBase
-
spliterator
-
elements
-
scope
-
isAccessibleBy
-
byteSize
-
asSlice
-
asSlice
-
asSlice
-
asSlice
-
reinterpret
-
reinterpret
-
reinterpret
-
isReadOnly
-
asReadOnly
-
isNative
-
isMapped
-
asOverlappingSlice
-
fill
-
copyFrom
-
mismatch
-
isLoaded
-
load
-
unload
-
force
-
asByteBuffer
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
toArray
-
getString
-
getString
-
setString
-
setString
-
ofBuffer
-
ofArray
-
ofArray
-
ofArray
-
ofArray
-
ofArray
-
ofArray
-
ofArray
-
ofAddress
-
copy
-
copy
-
get
-
set
-
get
-
set
-
get
-
set
-
get
-
set
-
get
-
set
-
get
-
set
-
get
-
set
-
get
-
set
-
get
-
set
-
getAtIndex
-
getAtIndex
-
getAtIndex
-
setAtIndex
-
getAtIndex
-
setAtIndex
-
setAtIndex
-
setAtIndex
-
getAtIndex
-
setAtIndex
-
getAtIndex
-
setAtIndex
-
getAtIndex
-
setAtIndex
-
getAtIndex
-
setAtIndex
-
getAtIndex
-
setAtIndex
-
equals
-
hashCode
-
copy
-
copy
-
mismatch
-