# Uses of Interface
jdk.incubator.foreign.MemorySegment

Packages that use MemorySegment
Package
Description
jdk.incubator.foreign
Classes to support low-level and efficient foreign memory/function access, directly from Java.

- ## Uses of MemorySegment in jdk.incubator.foreign

  Methods in jdk.incubator.foreign that return MemorySegment
  Modifier and Type
  Method
  Description
  `default MemorySegment`
  SegmentAllocator.`allocate(long bytesSize)`
  Allocate a block of memory with given size, with default alignment (1-byte aligned).
  `MemorySegment`
  SegmentAllocator.`allocate(long bytesSize, long bytesAlignment)`
  Allocate a block of memory with given size and alignment constraint.
  `default MemorySegment`
  SegmentAllocator.`allocate(MemoryLayout layout)`
  Allocate a block of memory with given layout.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, byte value)`
  Allocate a block of memory with given layout and initialize it with given byte value.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, char value)`
  Allocate a block of memory with given layout and initialize it with given char value.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, double value)`
  Allocate a block of memory with given layout and initialize it with given double value.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, float value)`
  Allocate a block of memory with given layout and initialize it with given float value.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, int value)`
  Allocate a block of memory with given layout and initialize it with given int value.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, long value)`
  Allocate a block of memory with given layout and initialize it with given long value.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, short value)`
  Allocate a block of memory with given layout and initialize it with given short value.
  `default MemorySegment`
  SegmentAllocator.`allocate(ValueLayout layout, Addressable value)`
  Allocate a block of memory with given layout and initialize it with given address value (expressed as an `Addressable` instance).
  `default MemorySegment`
  SegmentAllocator.`allocateArray(MemoryLayout elementLayout, long count)`
  Allocate a block of memory corresponding to an array with given element layout and size.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, byte[] array)`
  Allocate a block of memory with given layout and initialize it with given byte array.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, char[] array)`
  Allocate a block of memory with given layout and initialize it with given char array.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, double[] array)`
  Allocate a block of memory with given layout and initialize it with given double array.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, float[] array)`
  Allocate a block of memory with given layout and initialize it with given float array.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, int[] array)`
  Allocate a block of memory with given layout and initialize it with given int array.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, long[] array)`
  Allocate a block of memory with given layout and initialize it with given long array.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, short[] array)`
  Allocate a block of memory with given layout and initialize it with given short array.
  `default MemorySegment`
  SegmentAllocator.`allocateArray(ValueLayout elementLayout, Addressable[] array)`
  Allocate a block of memory with given layout and initialize it with given address array.
  `static MemorySegment`
  MemorySegment.`allocateNative(long bytesSize, long alignmentBytes, ResourceScope scope)`
  Creates a new confined native memory segment that models a newly allocated block of off-heap memory with given size (in bytes), alignment constraint (in bytes) and resource scope.
  `static MemorySegment`
  MemorySegment.`allocateNative(long bytesSize, ResourceScope scope)`
  Creates a new confined native memory segment that models a newly allocated block of off-heap memory with given size (in bytes) and resource scope.
  `static MemorySegment`
  MemorySegment.`allocateNative(MemoryLayout layout, ResourceScope scope)`
  Creates a new confined native memory segment that models a newly allocated block of off-heap memory with given layout and resource scope.
  `MemorySegment`
  MemorySegment.`asReadOnly()`
  Obtains a read-only view of this segment.
  `MemorySegment`
  MemoryAddress.`asSegment(long bytesSize, Runnable cleanupAction, ResourceScope scope)`
  Returns a new native memory segment with given size and resource scope (replacing the scope already associated with this address), and whose base address is this address.
  `MemorySegment`
  MemoryAddress.`asSegment(long bytesSize, ResourceScope scope)`
  Returns a new native memory segment with given size and resource scope (replacing the scope already associated with this address), and whose base address is this address.
  `default MemorySegment`
  MemorySegment.`asSlice(long offset)`
  Obtains a new memory segment view whose base address is the same as the base address of this segment plus a given offset, and whose new size is computed by subtracting the specified offset from this segment size.
  `MemorySegment`
  MemorySegment.`asSlice(long offset, long newSize)`
  Obtains a new memory segment view whose base address is the same as the base address of this segment plus a given offset, and whose new size is specified by the given argument.
  `default MemorySegment`
  MemorySegment.`asSlice(MemoryAddress newBase)`
  Obtains a new memory segment view whose base address is the given address, and whose new size is computed by subtracting the address offset relative to this segment (see `MemoryAddress.segmentOffset(MemorySegment)`) from this segment size.
  `default MemorySegment`
  MemorySegment.`asSlice(MemoryAddress newBase, long newSize)`
  Obtains a new memory segment view whose base address is the given address, and whose new size is specified by the given argument.
  `MemorySegment`
  MemorySegment.`fill(byte value)`
  Fills a value into this memory segment.
  `static MemorySegment`
  MemorySegment.`globalNativeSegment()`
  Returns a native memory segment whose base address is `MemoryAddress.NULL` and whose size is `Long.MAX_VALUE`.
  `static MemorySegment`
  MemorySegment.`mapFile(Path path, long bytesOffset, long bytesSize, FileChannel.MapMode mapMode, ResourceScope scope)`
  Creates a new mapped memory segment that models a memory-mapped region of a file from a given path.
  `static MemorySegment`
  MemorySegment.`ofArray(byte[] arr)`
  Creates a new confined array memory segment that models the memory associated with a given heap-allocated byte array.
  `static MemorySegment`
  MemorySegment.`ofArray(char[] arr)`
  Creates a new confined array memory segment that models the memory associated with a given heap-allocated char array.
  `static MemorySegment`
  MemorySegment.`ofArray(double[] arr)`
  Creates a new confined array memory segment that models the memory associated with a given heap-allocated double array.
  `static MemorySegment`
  MemorySegment.`ofArray(float[] arr)`
  Creates a new confined array memory segment that models the memory associated with a given heap-allocated float array.
  `static MemorySegment`
  MemorySegment.`ofArray(int[] arr)`
  Creates a new confined array memory segment that models the memory associated with a given heap-allocated int array.
  `static MemorySegment`
  MemorySegment.`ofArray(long[] arr)`
  Creates a new confined array memory segment that models the memory associated with a given heap-allocated long array.
  `static MemorySegment`
  MemorySegment.`ofArray(short[] arr)`
  Creates a new confined array memory segment that models the memory associated with a given heap-allocated short array.
  `static MemorySegment`
  MemorySegment.`ofByteBuffer(ByteBuffer bb)`
  Creates a new confined buffer memory segment that models the memory associated with the given byte buffer.
  `static MemorySegment`
  CLinker.`toCString(String str, ResourceScope scope)`
  Converts a Java string into a UTF-8 encoded, null-terminated C string, storing the result into a native memory segment associated with the provided resource scope.
  `static MemorySegment`
  CLinker.`toCString(String str, SegmentAllocator allocator)`
  Converts a Java string into a UTF-8 encoded, null-terminated C string, storing the result into a native memory segment allocated using the provided allocator.
  `MemorySegment`
  CLinker.VaList.`vargAsSegment(MemoryLayout layout, ResourceScope scope)`
  Reads the next value as a `MemorySegment`, and advances this va list's position.
  `MemorySegment`
  CLinker.VaList.`vargAsSegment(MemoryLayout layout, SegmentAllocator allocator)`
  Reads the next value as a `MemorySegment`, and advances this va list's position.
  Methods in jdk.incubator.foreign that return types with arguments of type MemorySegment
  Modifier and Type
  Method
  Description
  `Stream<MemorySegment>`
  MemorySegment.`elements(MemoryLayout elementLayout)`
  Returns a sequential `Stream` over disjoint slices (whose size matches that of the specified layout) in this segment.
  `Spliterator<MemorySegment>`
  MemorySegment.`spliterator(MemoryLayout elementLayout)`
  Returns a spliterator for this memory segment.
  Methods in jdk.incubator.foreign with parameters of type MemorySegment
  Modifier and Type
  Method
  Description
  `void`
  MemorySegment.`copyFrom(MemorySegment src)`
  Performs a bulk copy from given source segment to this segment.
  `static MemoryAddress`
  MemoryAccess.`getAddress(MemorySegment segment)`
  Reads a memory address from given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static MemoryAddress`
  MemoryAccess.`getAddressAtIndex(MemorySegment segment, long index)`
  Reads a memory address from given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static MemoryAddress`
  MemoryAccess.`getAddressAtOffset(MemorySegment segment, long offset)`
  Reads a memory address from given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static byte`
  MemoryAccess.`getByte(MemorySegment segment)`
  Reads a byte from given segment.
  `static byte`
  MemoryAccess.`getByteAtOffset(MemorySegment segment, long offset)`
  Reads a byte from given segment and offset.
  `static char`
  MemoryAccess.`getChar(MemorySegment segment)`
  Reads a char from given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static char`
  MemoryAccess.`getChar(MemorySegment segment, ByteOrder order)`
  Reads a char from given segment, with given byte order.
  `static char`
  MemoryAccess.`getCharAtIndex(MemorySegment segment, long index)`
  Reads a char from given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static char`
  MemoryAccess.`getCharAtIndex(MemorySegment segment, long index, ByteOrder order)`
  Reads a char from given segment and element index, with given byte order.
  `static char`
  MemoryAccess.`getCharAtOffset(MemorySegment segment, long offset)`
  Reads a char from given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static char`
  MemoryAccess.`getCharAtOffset(MemorySegment segment, long offset, ByteOrder order)`
  Reads a char from given segment and offset with given byte order.
  `static double`
  MemoryAccess.`getDouble(MemorySegment segment)`
  Reads a double from given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static double`
  MemoryAccess.`getDouble(MemorySegment segment, ByteOrder order)`
  Reads a double from given segment, with given byte order.
  `static double`
  MemoryAccess.`getDoubleAtIndex(MemorySegment segment, long index)`
  Reads a double from given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static double`
  MemoryAccess.`getDoubleAtIndex(MemorySegment segment, long index, ByteOrder order)`
  Reads a double from given segment and element index, with given byte order.
  `static double`
  MemoryAccess.`getDoubleAtOffset(MemorySegment segment, long offset)`
  Reads a double from given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static double`
  MemoryAccess.`getDoubleAtOffset(MemorySegment segment, long offset, ByteOrder order)`
  Reads a double from given segment and offset with given byte order.
  `static float`
  MemoryAccess.`getFloat(MemorySegment segment)`
  Reads a float from given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static float`
  MemoryAccess.`getFloat(MemorySegment segment, ByteOrder order)`
  Reads a float from given segment, with given byte order.
  `static float`
  MemoryAccess.`getFloatAtIndex(MemorySegment segment, long index)`
  Reads a float from given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static float`
  MemoryAccess.`getFloatAtIndex(MemorySegment segment, long index, ByteOrder order)`
  Reads a float from given segment and element index, with given byte order.
  `static float`
  MemoryAccess.`getFloatAtOffset(MemorySegment segment, long offset)`
  Reads a float from given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static float`
  MemoryAccess.`getFloatAtOffset(MemorySegment segment, long offset, ByteOrder order)`
  Reads a float from given segment and offset with given byte order.
  `static int`
  MemoryAccess.`getInt(MemorySegment segment)`
  Reads an int from given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static int`
  MemoryAccess.`getInt(MemorySegment segment, ByteOrder order)`
  Reads an int from given segment, with given byte order.
  `static int`
  MemoryAccess.`getIntAtIndex(MemorySegment segment, long index)`
  Reads an int from given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static int`
  MemoryAccess.`getIntAtIndex(MemorySegment segment, long index, ByteOrder order)`
  Reads an int from given segment and element index, with given byte order.
  `static int`
  MemoryAccess.`getIntAtOffset(MemorySegment segment, long offset)`
  Reads an int from given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static int`
  MemoryAccess.`getIntAtOffset(MemorySegment segment, long offset, ByteOrder order)`
  Reads an int from given segment and offset with given byte order.
  `static long`
  MemoryAccess.`getLong(MemorySegment segment)`
  Reads a long from given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static long`
  MemoryAccess.`getLong(MemorySegment segment, ByteOrder order)`
  Reads a long from given segment, with given byte order.
  `static long`
  MemoryAccess.`getLongAtIndex(MemorySegment segment, long index)`
  Reads a long from given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static long`
  MemoryAccess.`getLongAtIndex(MemorySegment segment, long index, ByteOrder order)`
  Reads a long from given segment and element index, with given byte order.
  `static long`
  MemoryAccess.`getLongAtOffset(MemorySegment segment, long offset)`
  Reads a long from given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static long`
  MemoryAccess.`getLongAtOffset(MemorySegment segment, long offset, ByteOrder order)`
  Reads a long from given segment and offset with given byte order.
  `static short`
  MemoryAccess.`getShort(MemorySegment segment)`
  Reads a short from given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static short`
  MemoryAccess.`getShort(MemorySegment segment, ByteOrder order)`
  Reads a short from given segment, with given byte order.
  `static short`
  MemoryAccess.`getShortAtIndex(MemorySegment segment, long index)`
  Reads a short from given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static short`
  MemoryAccess.`getShortAtIndex(MemorySegment segment, long index, ByteOrder order)`
  Reads a short from given segment and element index, with given byte order.
  `static short`
  MemoryAccess.`getShortAtOffset(MemorySegment segment, long offset)`
  Reads a short from given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static short`
  MemoryAccess.`getShortAtOffset(MemorySegment segment, long offset, ByteOrder order)`
  Reads a short from given segment and offset with given byte order.
  `long`
  MemorySegment.`mismatch(MemorySegment other)`
  Finds and returns the offset, in bytes, of the first mismatch between this segment and a given other segment.
  `static SegmentAllocator`
  SegmentAllocator.`ofSegment(MemorySegment segment)`
  Returns a segment allocator which responds to allocation requests by recycling a single segment; that is, each new allocation request will return a new slice starting at the segment offset `0` (alignment constraints are ignored by this allocator).
  `long`
  MemoryAddress.`segmentOffset(MemorySegment segment)`
  Returns the offset of this memory address into the given segment.
  `static void`
  MemoryAccess.`setAddress(MemorySegment segment, Addressable value)`
  Writes a memory address at given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setAddressAtIndex(MemorySegment segment, long index, Addressable value)`
  Writes a memory address at given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setAddressAtOffset(MemorySegment segment, long offset, Addressable value)`
  Writes a memory address at given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setByte(MemorySegment segment, byte value)`
  Writes a byte at given segment.
  `static void`
  MemoryAccess.`setByteAtOffset(MemorySegment segment, long offset, byte value)`
  Writes a byte at given segment and offset.
  `static void`
  MemoryAccess.`setChar(MemorySegment segment, char value)`
  Writes a char at given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setChar(MemorySegment segment, ByteOrder order, char value)`
  Writes a char at given segment, with given byte order.
  `static void`
  MemoryAccess.`setCharAtIndex(MemorySegment segment, long index, char value)`
  Writes a char at given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setCharAtIndex(MemorySegment segment, long index, ByteOrder order, char value)`
  Writes a char at given segment and element index, with given byte order.
  `static void`
  MemoryAccess.`setCharAtOffset(MemorySegment segment, long offset, char value)`
  Writes a char at given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setCharAtOffset(MemorySegment segment, long offset, ByteOrder order, char value)`
  Writes a char at given segment and offset with given byte order.
  `static void`
  MemoryAccess.`setDouble(MemorySegment segment, double value)`
  Writes a double at given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setDouble(MemorySegment segment, ByteOrder order, double value)`
  Writes a double at given segment, with given byte order.
  `static void`
  MemoryAccess.`setDoubleAtIndex(MemorySegment segment, long index, double value)`
  Writes a double at given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setDoubleAtIndex(MemorySegment segment, long index, ByteOrder order, double value)`
  Writes a double at given segment and element index, with given byte order.
  `static void`
  MemoryAccess.`setDoubleAtOffset(MemorySegment segment, long offset, double value)`
  Writes a double at given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setDoubleAtOffset(MemorySegment segment, long offset, ByteOrder order, double value)`
  Writes a double at given segment and offset with given byte order.
  `static void`
  MemoryAccess.`setFloat(MemorySegment segment, float value)`
  Writes a float at given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setFloat(MemorySegment segment, ByteOrder order, float value)`
  Writes a float at given segment, with given byte order.
  `static void`
  MemoryAccess.`setFloatAtIndex(MemorySegment segment, long index, float value)`
  Writes a float at given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setFloatAtIndex(MemorySegment segment, long index, ByteOrder order, float value)`
  Writes a float at given segment and element index, with given byte order.
  `static void`
  MemoryAccess.`setFloatAtOffset(MemorySegment segment, long offset, float value)`
  Writes a float at given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setFloatAtOffset(MemorySegment segment, long offset, ByteOrder order, float value)`
  Writes a float at given segment and offset with given byte order.
  `static void`
  MemoryAccess.`setInt(MemorySegment segment, int value)`
  Writes an int at given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setInt(MemorySegment segment, ByteOrder order, int value)`
  Writes an int at given segment, with given byte order.
  `static void`
  MemoryAccess.`setIntAtIndex(MemorySegment segment, long index, int value)`
  Writes an int at given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setIntAtIndex(MemorySegment segment, long index, ByteOrder order, int value)`
  Writes an int at given segment and element index, with given byte order.
  `static void`
  MemoryAccess.`setIntAtOffset(MemorySegment segment, long offset, int value)`
  Writes an int at given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setIntAtOffset(MemorySegment segment, long offset, ByteOrder order, int value)`
  Writes an int at given segment and offset with given byte order.
  `static void`
  MemoryAccess.`setLong(MemorySegment segment, long value)`
  Writes a long at given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setLong(MemorySegment segment, ByteOrder order, long value)`
  Writes a long at given segment, with given byte order.
  `static void`
  MemoryAccess.`setLongAtIndex(MemorySegment segment, long index, long value)`
  Writes a long at given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setLongAtIndex(MemorySegment segment, long index, ByteOrder order, long value)`
  Writes a long at given segment and element index, with given byte order.
  `static void`
  MemoryAccess.`setLongAtOffset(MemorySegment segment, long offset, long value)`
  Writes a long at given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setLongAtOffset(MemorySegment segment, long offset, ByteOrder order, long value)`
  Writes a long at given segment and offset with given byte order.
  `static void`
  MemoryAccess.`setShort(MemorySegment segment, short value)`
  Writes a short at given segment, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setShort(MemorySegment segment, ByteOrder order, short value)`
  Writes a short at given segment, with given byte order.
  `static void`
  MemoryAccess.`setShortAtIndex(MemorySegment segment, long index, short value)`
  Writes a short at given segment and element index, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setShortAtIndex(MemorySegment segment, long index, ByteOrder order, short value)`
  Writes a short at given segment and element index, with given byte order.
  `static void`
  MemoryAccess.`setShortAtOffset(MemorySegment segment, long offset, short value)`
  Writes a short at given segment and offset, with byte order set to `ByteOrder.nativeOrder()`.
  `static void`
  MemoryAccess.`setShortAtOffset(MemorySegment segment, long offset, ByteOrder order, short value)`
  Writes a short at given segment and offset with given byte order.
  `static String`
  CLinker.`toJavaString(MemorySegment addr)`
  Converts a UTF-8 encoded, null-terminated C string stored at given address into a Java string.
  `CLinker.VaList.Builder`
  CLinker.VaList.Builder.`vargFromSegment(GroupLayout layout, MemorySegment value)`
  Adds a native value represented as a `MemorySegment` to the C `va_list` being constructed.