Class MemoryAccess
public final class MemoryAccess extends Object
The most primitive accessors (see getIntAtOffset(MemorySegment, long, ByteOrder)
) take a segment, an offset (expressed in bytes) and a byte order. The final address at which the dereference will occur will be computed by offsetting the base address by the specified offset, as if by calling MemoryAddress.addOffset(long)
on the specified base address.
In cases where no offset is required, overloads are provided (see getInt(MemorySegment, ByteOrder)
) so that clients can omit the offset coordinate.
To help dereferencing in array-like use cases (e.g. where the layout of a given memory segment is a sequence layout of given size an element count), higher-level overloads are also provided (see getIntAtIndex(MemorySegment, long, ByteOrder)
), which take a segment and a logical element index. The formula to obtain the byte offset O
from an index I
is given by O = I * S
where S
is the size (expressed in bytes) of the element to be dereferenced.
In cases where native byte order is preferred, overloads are provided (see getIntAtOffset(MemorySegment, long)
) so that clients can omit the byte order parameter.
Unless otherwise specified, passing a null
argument, or an array argument containing one or more null
elements to a method in this class causes a NullPointerException
to be thrown.
Method Summary
Modifier and Type | Method | Description |
---|---|---|
static MemoryAddress |
getAddress |
Reads a memory address from given segment, with byte order set to ByteOrder.nativeOrder() . |
static MemoryAddress |
getAddressAtIndex |
Reads a memory address from given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static MemoryAddress |
getAddressAtOffset |
Reads a memory address from given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static byte |
getByte |
Reads a byte from given segment. |
static byte |
getByteAtOffset |
Reads a byte from given segment and offset. |
static char |
getChar |
Reads a char from given segment, with byte order set to ByteOrder.nativeOrder() . |
static char |
getChar |
Reads a char from given segment, with given byte order. |
static char |
getCharAtIndex |
Reads a char from given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static char |
getCharAtIndex |
Reads a char from given segment and element index, with given byte order. |
static char |
getCharAtOffset |
Reads a char from given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static char |
getCharAtOffset |
Reads a char from given segment and offset with given byte order. |
static double |
getDouble |
Reads a double from given segment, with byte order set to ByteOrder.nativeOrder() . |
static double |
getDouble |
Reads a double from given segment, with given byte order. |
static double |
getDoubleAtIndex |
Reads a double from given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static double |
getDoubleAtIndex |
Reads a double from given segment and element index, with given byte order. |
static double |
getDoubleAtOffset |
Reads a double from given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static double |
getDoubleAtOffset |
Reads a double from given segment and offset with given byte order. |
static float |
getFloat |
Reads a float from given segment, with byte order set to ByteOrder.nativeOrder() . |
static float |
getFloat |
Reads a float from given segment, with given byte order. |
static float |
getFloatAtIndex |
Reads a float from given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static float |
getFloatAtIndex |
Reads a float from given segment and element index, with given byte order. |
static float |
getFloatAtOffset |
Reads a float from given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static float |
getFloatAtOffset |
Reads a float from given segment and offset with given byte order. |
static int |
getInt |
Reads an int from given segment, with byte order set to ByteOrder.nativeOrder() . |
static int |
getInt |
Reads an int from given segment, with given byte order. |
static int |
getIntAtIndex |
Reads an int from given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static int |
getIntAtIndex |
Reads an int from given segment and element index, with given byte order. |
static int |
getIntAtOffset |
Reads an int from given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static int |
getIntAtOffset |
Reads an int from given segment and offset with given byte order. |
static long |
getLong |
Reads a long from given segment, with byte order set to ByteOrder.nativeOrder() . |
static long |
getLong |
Reads a long from given segment, with given byte order. |
static long |
getLongAtIndex |
Reads a long from given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static long |
getLongAtIndex |
Reads a long from given segment and element index, with given byte order. |
static long |
getLongAtOffset |
Reads a long from given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static long |
getLongAtOffset |
Reads a long from given segment and offset with given byte order. |
static short |
getShort |
Reads a short from given segment, with byte order set to ByteOrder.nativeOrder() . |
static short |
getShort |
Reads a short from given segment, with given byte order. |
static short |
getShortAtIndex |
Reads a short from given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static short |
getShortAtIndex |
Reads a short from given segment and element index, with given byte order. |
static short |
getShortAtOffset |
Reads a short from given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static short |
getShortAtOffset |
Reads a short from given segment and offset with given byte order. |
static void |
setAddress |
Writes a memory address at given segment, with byte order set to ByteOrder.nativeOrder() . |
static void |
setAddressAtIndex |
Writes a memory address at given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static void |
setAddressAtOffset |
Writes a memory address at given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static void |
setByte |
Writes a byte at given segment. |
static void |
setByteAtOffset |
Writes a byte at given segment and offset. |
static void |
setChar |
Writes a char at given segment, with byte order set to ByteOrder.nativeOrder() . |
static void |
setChar |
Writes a char at given segment, with given byte order. |
static void |
setCharAtIndex |
Writes a char at given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static void |
setCharAtIndex |
Writes a char at given segment and element index, with given byte order. |
static void |
setCharAtOffset |
Writes a char at given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static void |
setCharAtOffset |
Writes a char at given segment and offset with given byte order. |
static void |
setDouble |
Writes a double at given segment, with byte order set to ByteOrder.nativeOrder() . |
static void |
setDouble |
Writes a double at given segment, with given byte order. |
static void |
setDoubleAtIndex |
Writes a double at given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static void |
setDoubleAtIndex |
Writes a double at given segment and element index, with given byte order. |
static void |
setDoubleAtOffset |
Writes a double at given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static void |
setDoubleAtOffset |
Writes a double at given segment and offset with given byte order. |
static void |
setFloat |
Writes a float at given segment, with byte order set to ByteOrder.nativeOrder() . |
static void |
setFloat |
Writes a float at given segment, with given byte order. |
static void |
setFloatAtIndex |
Writes a float at given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static void |
setFloatAtIndex |
Writes a float at given segment and element index, with given byte order. |
static void |
setFloatAtOffset |
Writes a float at given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static void |
setFloatAtOffset |
Writes a float at given segment and offset with given byte order. |
static void |
setInt |
Writes an int at given segment, with byte order set to ByteOrder.nativeOrder() . |
static void |
setInt |
Writes an int at given segment, with given byte order. |
static void |
setIntAtIndex |
Writes an int at given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static void |
setIntAtIndex |
Writes an int at given segment and element index, with given byte order. |
static void |
setIntAtOffset |
Writes an int at given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static void |
setIntAtOffset |
Writes an int at given segment and offset with given byte order. |
static void |
setLong |
Writes a long at given segment, with byte order set to ByteOrder.nativeOrder() . |
static void |
setLong |
Writes a long at given segment, with given byte order. |
static void |
setLongAtIndex |
Writes a long at given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static void |
setLongAtIndex |
Writes a long at given segment and element index, with given byte order. |
static void |
setLongAtOffset |
Writes a long at given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static void |
setLongAtOffset |
Writes a long at given segment and offset with given byte order. |
static void |
setShort |
Writes a short at given segment, with byte order set to ByteOrder.nativeOrder() . |
static void |
setShort |
Writes a short at given segment, with given byte order. |
static void |
setShortAtIndex |
Writes a short at given segment and element index, with byte order set to ByteOrder.nativeOrder() . |
static void |
setShortAtIndex |
Writes a short at given segment and element index, with given byte order. |
static void |
setShortAtOffset |
Writes a short at given segment and offset, with byte order set to ByteOrder.nativeOrder() . |
static void |
setShortAtOffset |
Writes a short at given segment and offset with given byte order. |
Method Details
getByteAtOffset
public static byte getByteAtOffset(MemorySegment segment, long offset)
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- a byte value read from
segment
.
setByteAtOffset
public static void setByteAtOffset(MemorySegment segment, long offset, byte value)
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the byte value to be written.
getCharAtOffset
public static char getCharAtOffset(MemorySegment segment, long offset)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
getCharAtOffset(segment, offset, ByteOrder.nativeOrder());
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- a char value read from
segment
.
setCharAtOffset
public static void setCharAtOffset(MemorySegment segment, long offset, char value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setCharAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the char value to be written.
getShortAtOffset
public static short getShortAtOffset(MemorySegment segment, long offset)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
getShortAtOffset(segment, offset, ByteOrder.nativeOrder());
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- a short value read from
segment
.
setShortAtOffset
public static void setShortAtOffset(MemorySegment segment, long offset, short value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setShortAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the short value to be written.
getIntAtOffset
public static int getIntAtOffset(MemorySegment segment, long offset)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
getIntAtOffset(segment, offset, ByteOrder.nativeOrder());
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- an int value read from
segment
.
setIntAtOffset
public static void setIntAtOffset(MemorySegment segment, long offset, int value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setIntAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the int value to be written.
getFloatAtOffset
public static float getFloatAtOffset(MemorySegment segment, long offset)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
getFloatAtOffset(segment, offset, ByteOrder.nativeOrder());
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- a float value read from
segment
.
setFloatAtOffset
public static void setFloatAtOffset(MemorySegment segment, long offset, float value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setFloatAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the float value to be written.
getLongAtOffset
public static long getLongAtOffset(MemorySegment segment, long offset)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
getLongAtOffset(segment, offset, ByteOrder.nativeOrder());
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- a long value read from
segment
.
setLongAtOffset
public static void setLongAtOffset(MemorySegment segment, long offset, long value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setLongAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the long value to be written.
getDoubleAtOffset
public static double getDoubleAtOffset(MemorySegment segment, long offset)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
getDoubleAtOffset(segment, offset, ByteOrder.nativeOrder());
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- a double value read from
segment
.
setDoubleAtOffset
public static void setDoubleAtOffset(MemorySegment segment, long offset, double value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setDoubleAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the double value to be written.
getAddressAtOffset
public static MemoryAddress getAddressAtOffset(MemorySegment segment, long offset)
ByteOrder.nativeOrder()
. This is equivalent (e.g. on a 64-bit platform) to the following code:
VarHandle handle = MemoryHandles.asAddressHandle(MemoryHandles.varHandle(long.class, ByteOrder.nativeOrder())); MemoryAddress value = (MemoryAddress)handle.get(segment, offset);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. - Returns:
- a memory address read from
segment
.
setAddressAtOffset
public static void setAddressAtOffset(MemorySegment segment, long offset, Addressable value)
ByteOrder.nativeOrder()
. This is equivalent (e.g. on a 64-bit platform) to the following code:
VarHandle handle = MemoryHandles.asAddressHandle(MemoryHandles.varHandle(long.class, ByteOrder.nativeOrder())); handle.set(segment, offset, value.address());
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
value
- the memory address to be written (expressed as anAddressable
instance).
getCharAtOffset
public static char getCharAtOffset(MemorySegment segment, long offset, ByteOrder order)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(char.class, 1, order); char value = (char)handle.get(segment, offset);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. - Returns:
- a char value read from
segment
.
setCharAtOffset
public static void setCharAtOffset(MemorySegment segment, long offset, ByteOrder order, char value)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(char.class, 1, order); handle.set(segment, offset, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. -
value
- the char value to be written.
getShortAtOffset
public static short getShortAtOffset(MemorySegment segment, long offset, ByteOrder order)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(short.class, 1, order); short value = (short)handle.get(segment, offset);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. - Returns:
- a short value read from
segment
.
setShortAtOffset
public static void setShortAtOffset(MemorySegment segment, long offset, ByteOrder order, short value)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(short.class, 1, order); handle.set(segment, offset, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. -
value
- the short value to be written.
getIntAtOffset
public static int getIntAtOffset(MemorySegment segment, long offset, ByteOrder order)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(int.class, 1, order); int value = (int)handle.get(segment, offset);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. - Returns:
- an int value read from
segment
.
setIntAtOffset
public static void setIntAtOffset(MemorySegment segment, long offset, ByteOrder order, int value)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(int.class, 1, order); handle.set(segment, offset, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. -
value
- the int value to be written.
getFloatAtOffset
public static float getFloatAtOffset(MemorySegment segment, long offset, ByteOrder order)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(float.class, 1, order); float value = (float)handle.get(segment, offset);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. - Returns:
- a float value read from
segment
.
setFloatAtOffset
public static void setFloatAtOffset(MemorySegment segment, long offset, ByteOrder order, float value)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(float.class, 1, order); handle.set(segment, offset, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. -
value
- the float value to be written.
getLongAtOffset
public static long getLongAtOffset(MemorySegment segment, long offset, ByteOrder order)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(long.class, 1, order); long value = (long)handle.get(segment, offset);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. - Returns:
- a long value read from
segment
.
setLongAtOffset
public static void setLongAtOffset(MemorySegment segment, long offset, ByteOrder order, long value)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(long.class, 1, order); handle.set(segment, offset, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. -
value
- the long value to be written.
getDoubleAtOffset
public static double getDoubleAtOffset(MemorySegment segment, long offset, ByteOrder order)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(double.class, 1, order); double value = (double)handle.get(segment, offset);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. - Returns:
- a double value read from
segment
.
setDoubleAtOffset
public static void setDoubleAtOffset(MemorySegment segment, long offset, ByteOrder order, double value)
This is equivalent to the following code:
VarHandle handle = MemoryHandles.varHandle(double.class, 1, order); handle.set(segment, offset, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
offset
- offset in bytes (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(offset)
. -
order
- the specified byte order. -
value
- the double value to be written.
getByte
public static byte getByte(MemorySegment segment)
This is equivalent to the following code:
byte value = getByteAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- a byte value read from
segment
.
setByte
public static void setByte(MemorySegment segment, byte value)
This is equivalent to the following code:
setByteAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the byte value to be written.
getChar
public static char getChar(MemorySegment segment)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
char value = getCharAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- a char value read from
segment
.
setChar
public static void setChar(MemorySegment segment, char value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setCharAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the char value to be written.
getShort
public static short getShort(MemorySegment segment)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
short value = getShortAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- a short value read from
segment
.
setShort
public static void setShort(MemorySegment segment, short value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setShortAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the short value to be written.
getInt
public static int getInt(MemorySegment segment)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
int value = getIntAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- an int value read from
segment
.
setInt
public static void setInt(MemorySegment segment, int value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setIntAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the int value to be written.
getFloat
public static float getFloat(MemorySegment segment)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
float value = getFloatAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- a float value read from
segment
.
setFloat
public static void setFloat(MemorySegment segment, float value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setFloatAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the float value to be written.
getLong
public static long getLong(MemorySegment segment)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
long value = getLongAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- a long value read from
segment
.
setLong
public static void setLong(MemorySegment segment, long value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setLongAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the long value to be written.
getDouble
public static double getDouble(MemorySegment segment)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
double value = getDoubleAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- a double value read from
segment
.
setDouble
public static void setDouble(MemorySegment segment, double value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setDoubleAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the double value to be written.
getAddress
public static MemoryAddress getAddress(MemorySegment segment)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
MemoryAddress value = getAddressAtOffset(segment, 0L);
- Parameters:
-
segment
- the segment to be dereferenced. - Returns:
- a memory address read from
segment
.
setAddress
public static void setAddress(MemorySegment segment, Addressable value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setAddressAtOffset(segment, 0L, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
value
- the memory address to be written (expressed as anAddressable
instance).
getChar
public static char getChar(MemorySegment segment, ByteOrder order)
This is equivalent to the following code:
char value = getCharAtOffset(segment, 0L, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. - Returns:
- a char value read from
segment
.
setChar
public static void setChar(MemorySegment segment, ByteOrder order, char value)
This is equivalent to the following code:
setCharAtOffset(segment, 0L, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. -
value
- the char value to be written.
getShort
public static short getShort(MemorySegment segment, ByteOrder order)
This is equivalent to the following code:
short value = getShortAtOffset(segment, 0L, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. - Returns:
- a short value read from
segment
.
setShort
public static void setShort(MemorySegment segment, ByteOrder order, short value)
This is equivalent to the following code:
setShortAtOffset(segment, 0L, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. -
value
- the short value to be written.
getInt
public static int getInt(MemorySegment segment, ByteOrder order)
This is equivalent to the following code:
int value = getIntAtOffset(segment, 0L, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. - Returns:
- an int value read from
segment
.
setInt
public static void setInt(MemorySegment segment, ByteOrder order, int value)
This is equivalent to the following code:
setIntAtOffset(segment, 0L, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. -
value
- the int value to be written.
getFloat
public static float getFloat(MemorySegment segment, ByteOrder order)
This is equivalent to the following code:
float value = getFloatAtOffset(segment, 0L, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. - Returns:
- a float value read from
segment
.
setFloat
public static void setFloat(MemorySegment segment, ByteOrder order, float value)
This is equivalent to the following code:
setFloatAtOffset(segment, 0L, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. -
value
- the float value to be written.
getLong
public static long getLong(MemorySegment segment, ByteOrder order)
This is equivalent to the following code:
long value = getLongAtOffset(segment, 0L, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. - Returns:
- a long value read from
segment
.
setLong
public static void setLong(MemorySegment segment, ByteOrder order, long value)
This is equivalent to the following code:
setLongAtOffset(segment, 0L, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. -
value
- the long value to be written.
getDouble
public static double getDouble(MemorySegment segment, ByteOrder order)
This is equivalent to the following code:
double value = getDoubleAtOffset(segment, 0L, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. - Returns:
- a double value read from
segment
.
setDouble
public static void setDouble(MemorySegment segment, ByteOrder order, double value)
This is equivalent to the following code:
setDoubleAtOffset(segment, 0L, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
order
- the specified byte order. -
value
- the double value to be written.
getCharAtIndex
public static char getCharAtIndex(MemorySegment segment, long index)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
char value = getCharAtOffset(segment, 2 * index);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. - Returns:
- a char value read from
segment
at the element index specified byindex
.
setCharAtIndex
public static void setCharAtIndex(MemorySegment segment, long index, char value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setCharAtOffset(segment, 2 * index, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. -
value
- the char value to be written.
getShortAtIndex
public static short getShortAtIndex(MemorySegment segment, long index)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
short value = getShortAtOffset(segment, 2 * index);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. - Returns:
- a short value read from
segment
at the element index specified byindex
.
setShortAtIndex
public static void setShortAtIndex(MemorySegment segment, long index, short value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setShortAtOffset(segment, 2 * index, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. -
value
- the short value to be written.
getIntAtIndex
public static int getIntAtIndex(MemorySegment segment, long index)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
int value = getIntAtOffset(segment, 4 * index);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. - Returns:
- an int value read from
segment
at the element index specified byindex
.
setIntAtIndex
public static void setIntAtIndex(MemorySegment segment, long index, int value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setIntAtOffset(segment, 4 * index, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. -
value
- the int value to be written.
getFloatAtIndex
public static float getFloatAtIndex(MemorySegment segment, long index)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
float value = getFloatAtOffset(segment, 4 * index);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. - Returns:
- a float value read from
segment
at the element index specified byindex
.
setFloatAtIndex
public static void setFloatAtIndex(MemorySegment segment, long index, float value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setFloatAtOffset(segment, 4 * index, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. -
value
- the float value to be written.
getLongAtIndex
public static long getLongAtIndex(MemorySegment segment, long index)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
return getLongAtOffset(segment, 8 * index);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. - Returns:
- a long value read from
segment
at the element index specified byindex
.
setLongAtIndex
public static void setLongAtIndex(MemorySegment segment, long index, long value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setLongAtOffset(segment, 8 * index, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. -
value
- the long value to be written.
getDoubleAtIndex
public static double getDoubleAtIndex(MemorySegment segment, long index)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
return getDoubleAtOffset(segment, 8 * index);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. - Returns:
- a double value read from
segment
at the element index specified byindex
.
setDoubleAtIndex
public static void setDoubleAtIndex(MemorySegment segment, long index, double value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setDoubleAtOffset(segment, 8 * index, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. -
value
- the double value to be written.
getAddressAtIndex
public static MemoryAddress getAddressAtIndex(MemorySegment segment, long index)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
return getAddressAtOffset(segment, index * MemoryLayouts.ADDRESS.byteSize());
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. - Returns:
- a memory address read from
segment
at the element index specified byindex
.
setAddressAtIndex
public static void setAddressAtIndex(MemorySegment segment, long index, Addressable value)
ByteOrder.nativeOrder()
. This is equivalent to the following code:
setAddressAtOffset(segment, index * MemoryLayouts.ADDRESS.byteSize(), value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. -
value
- the memory address to be written (expressed as anAddressable
instance).
getCharAtIndex
public static char getCharAtIndex(MemorySegment segment, long index, ByteOrder order)
This is equivalent to the following code:
char value = getCharAtOffset(segment, 2 * index, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. -
order
- the specified byte order. - Returns:
- a char value read from
segment
at the element index specified byindex
.
setCharAtIndex
public static void setCharAtIndex(MemorySegment segment, long index, ByteOrder order, char value)
This is equivalent to the following code:
setCharAtOffset(segment, 2 * index, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. -
order
- the specified byte order. -
value
- the char value to be written.
getShortAtIndex
public static short getShortAtIndex(MemorySegment segment, long index, ByteOrder order)
This is equivalent to the following code:
short value = getShortAtOffset(segment, 2 * index, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. -
order
- the specified byte order. - Returns:
- a short value read from
segment
at the element index specified byindex
.
setShortAtIndex
public static void setShortAtIndex(MemorySegment segment, long index, ByteOrder order, short value)
This is equivalent to the following code:
setShortAtOffset(segment, 2 * index, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 2)
. -
order
- the specified byte order. -
value
- the short value to be written.
getIntAtIndex
public static int getIntAtIndex(MemorySegment segment, long index, ByteOrder order)
This is equivalent to the following code:
int value = getIntAtOffset(segment, 4 * index, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. -
order
- the specified byte order. - Returns:
- an int value read from
segment
at the element index specified byindex
.
setIntAtIndex
public static void setIntAtIndex(MemorySegment segment, long index, ByteOrder order, int value)
This is equivalent to the following code:
setIntAtOffset(segment, 4 * index, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. -
order
- the specified byte order. -
value
- the int value to be written.
getFloatAtIndex
public static float getFloatAtIndex(MemorySegment segment, long index, ByteOrder order)
This is equivalent to the following code:
float value = getFloatAtOffset(segment, 4 * index, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. -
order
- the specified byte order. - Returns:
- a float value read from
segment
at the element index specified byindex
.
setFloatAtIndex
public static void setFloatAtIndex(MemorySegment segment, long index, ByteOrder order, float value)
This is equivalent to the following code:
setFloatAtOffset(segment, 4 * index, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 4)
. -
order
- the specified byte order. -
value
- the float value to be written.
getLongAtIndex
public static long getLongAtIndex(MemorySegment segment, long index, ByteOrder order)
This is equivalent to the following code:
return getLongAtOffset(segment, 8 * index, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. -
order
- the specified byte order. - Returns:
- a long value read from
segment
at the element index specified byindex
.
setLongAtIndex
public static void setLongAtIndex(MemorySegment segment, long index, ByteOrder order, long value)
This is equivalent to the following code:
setLongAtOffset(segment, 8 * index, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. -
order
- the specified byte order. -
value
- the long value to be written.
getDoubleAtIndex
public static double getDoubleAtIndex(MemorySegment segment, long index, ByteOrder order)
This is equivalent to the following code:
return getDoubleAtOffset(segment, 8 * index, order);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. -
order
- the specified byte order. - Returns:
- a double value read from
segment
at the element index specified byindex
.
setDoubleAtIndex
public static void setDoubleAtIndex(MemorySegment segment, long index, ByteOrder order, double value)
This is equivalent to the following code:
setDoubleAtOffset(segment, 8 * index, order, value);
- Parameters:
-
segment
- the segment to be dereferenced. -
index
- element index (relative tosegment
). The final address of this read operation can be expressed assegment.address().addOffset(index * 8)
. -
order
- the specified byte order. -
value
- the double value to be written.
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/jdk.incubator.foreign/jdk/incubator/foreign/MemoryAccess.html