Uses of Interface java.lang.foreign.MemorySegment (Java SE 26 & JDK 26)
Description: use: module: java.base, package: java.lang.foreign, interface: MemorySegment

# Uses of Interface
java.lang.foreign.MemorySegment

Packages that use MemorySegment
Package
Description
java.lang.foreign
Provides low-level access to memory and functions outside the Java runtime.
java.nio.channels
Defines channels, which represent connections to entities that are capable of performing I/O operations, such as files and sockets; defines selectors, for multiplexed, non-blocking I/O operations.
jdk.incubator.vector
Incubating Feature. Will be removed in a future release.

- ## Uses of MemorySegment in java.lang.foreign

  Fields in java.lang.foreign declared as MemorySegment
  Modifier and Type
  Field
  Description
  `static final MemorySegment`
  MemorySegment.`NULL`
  A zero-length native segment modelling the `NULL` address.
  Methods in java.lang.foreign that return MemorySegment
  Modifier and Type
  Method
  Description
  `MemorySegment`
  Arena.`allocate(long byteSize, long byteAlignment)`
  Returns a native memory segment with the given size (in bytes) and alignment constraint (in bytes).
  `default MemorySegment`
  SegmentAllocator.`allocate(long byteSize)`
  Returns a new memory segment with the given `byteSize`.
  `MemorySegment`
  SegmentAllocator.`allocate(long byteSize, long byteAlignment)`
  Returns a new memory segment with the given `byteSize` and `byteAlignment`.
  `default MemorySegment`
  SegmentAllocator.`allocate(MemoryLayout layout)`
  Returns a new memory segment with the given layout.
  `default MemorySegment`
  SegmentAllocator.`allocate(MemoryLayout elementLayout, long count)`
  Returns a new memory segment with the given `elementLayout` and `count`.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(AddressLayout layout, MemorySegment value)`
  Returns a new memory segment initialized with the address of the provided memory segment.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfByte layout, byte value)`
  Returns a new memory segment initialized with the provided byte value.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfByte elementLayout, byte... elements)`
  Returns a new memory segment initialized with the elements in the provided byte array.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfChar layout, char value)`
  Returns a new memory segment initialized with the provided char value.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfChar elementLayout, char... elements)`
  Returns a new memory segment initialized with the elements in the provided char array.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfDouble layout, double value)`
  Returns a new memory segment initialized with the provided double value.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfDouble elementLayout, double... elements)`
  Returns a new memory segment initialized with the elements in the provided double array.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfFloat layout, float value)`
  Returns a new memory segment initialized with the provided float value.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfFloat elementLayout, float... elements)`
  Returns a new memory segment initialized with the elements in the provided float array.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfInt layout, int value)`
  Returns a new memory segment initialized with the provided int value.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfInt elementLayout, int... elements)`
  Returns a new memory segment initialized with the elements in the provided int array.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfLong layout, long value)`
  Returns a new memory segment initialized with the provided long value.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfLong elementLayout, long... elements)`
  Returns a new memory segment initialized with the elements in the provided long array.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfShort layout, short value)`
  Returns a new memory segment initialized with the provided short value.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout.OfShort elementLayout, short... elements)`
  Returns a new memory segment initialized with the elements in the provided short array.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout elementLayout, MemorySegment source, ValueLayout sourceElementLayout, long sourceOffset, long elementCount)`
  Returns a new memory segment initialized with the contents of the provided segment.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(String str)`
  Converts a Java string into a null-terminated C string using the UTF-8 charset, storing the result into a memory segment.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(String str, Charset charset)`
  Converts a Java string into a null-terminated C string using the provided charset, and storing the result into a memory segment.
  `MemorySegment`
  MemorySegment.`asReadOnly()`
  Returns a read-only view of this segment.
  `MemorySegment`
  MemorySegment.`asSlice(long offset)`
  Returns a slice of this memory segment, at the given offset.
  `MemorySegment`
  MemorySegment.`asSlice(long offset, long newSize)`
  Returns a slice of this memory segment, at the given offset.
  `MemorySegment`
  MemorySegment.`asSlice(long offset, long newSize, long byteAlignment)`
  Returns a slice of this memory segment, at the given offset, with the provided alignment constraint.
  `MemorySegment`
  MemorySegment.`asSlice(long offset, MemoryLayout layout)`
  Returns a slice of this memory segment with the given layout, at the given offset.
  `MemorySegment`
  MemorySegment.`copyFrom(MemorySegment src)`
  Performs a bulk copy from the given source segment to this segment.
  `MemorySegment`
  MemorySegment.`fill(byte value)`
  Fills the contents of this memory segment with the given value.
  `default MemorySegment`
  SymbolLookup.`findOrThrow(String name)`
  Returns the address of the symbol with the given name or throws an exception.
  `MemorySegment`
  MemorySegment.`get(AddressLayout layout, long offset)`
  Reads an address from this segment at the given offset, with the given layout.
  `MemorySegment`
  MemorySegment.`getAtIndex(AddressLayout layout, long index)`
  Reads an address from this segment at the given at the given index, scaled by the given layout size.
  `static MemorySegment`
  MemorySegment.`ofAddress(long address)`
  Creates a zero-length native segment from the given address value.
  `static MemorySegment`
  MemorySegment.`ofArray(byte[] byteArray)`
  Creates a heap segment backed by the on-heap region of memory that holds the given byte array.
  `static MemorySegment`
  MemorySegment.`ofArray(char[] charArray)`
  Creates a heap segment backed by the on-heap region of memory that holds the given char array.
  `static MemorySegment`
  MemorySegment.`ofArray(double[] doubleArray)`
  Creates a heap segment backed by the on-heap region of memory that holds the given double array.
  `static MemorySegment`
  MemorySegment.`ofArray(float[] floatArray)`
  Creates a heap segment backed by the on-heap region of memory that holds the given float array.
  `static MemorySegment`
  MemorySegment.`ofArray(int[] intArray)`
  Creates a heap segment backed by the on-heap region of memory that holds the given int array.
  `static MemorySegment`
  MemorySegment.`ofArray(long[] longArray)`
  Creates a heap segment backed by the on-heap region of memory that holds the given long array.
  `static MemorySegment`
  MemorySegment.`ofArray(short[] shortArray)`
  Creates a heap segment backed by the on-heap region of memory that holds the given short array.
  `static MemorySegment`
  MemorySegment.`ofBuffer(Buffer buffer)`
  Creates a memory segment that is backed by the same region of memory that backs the given `Buffer` instance.
  `MemorySegment`
  MemorySegment.`reinterpret(long newSize)`
  Restricted.
  Returns a new memory segment that has the same address and scope as this segment, but with the provided size.
  `MemorySegment`
  MemorySegment.`reinterpret(long newSize, Arena arena, Consumer<MemorySegment> cleanup)`
  Restricted.
  Returns a new segment with the same address as this segment, but with the provided size and the provided arena's scope.
  `MemorySegment`
  MemorySegment.`reinterpret(Arena arena, Consumer<MemorySegment> cleanup)`
  Restricted.
  Returns a new memory segment with the same address and size as this segment, but with the provided arena's scope.
  `MemorySegment`
  Linker.`upcallStub(MethodHandle target, FunctionDescriptor function, Arena arena, Linker.Option... options)`
  Restricted.
  Creates an upcall stub which can be passed to other foreign functions as a function pointer, associated with the given arena.
  Methods in java.lang.foreign that return types with arguments of type MemorySegment
  Modifier and Type
  Method
  Description
  `Optional<MemorySegment>`
  MemorySegment.`asOverlappingSlice(MemorySegment other)`
  Returns a slice of this segment that is the overlap between this and the provided segment.
  `Stream<MemorySegment>`
  MemorySegment.`elements(MemoryLayout elementLayout)`
  Returns a sequential `Stream` over disjoint slices (whose size matches that of the specified layout) in this segment.
  `Optional<MemorySegment>`
  SymbolLookup.`find(String name)`
  Returns the address of the symbol with the given name.
  `Spliterator<MemorySegment>`
  MemorySegment.`spliterator(MemoryLayout elementLayout)`
  Returns a spliterator for this memory segment.
  Methods in java.lang.foreign with parameters of type MemorySegment
  Modifier and Type
  Method
  Description
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(AddressLayout layout, MemorySegment value)`
  Returns a new memory segment initialized with the address of the provided memory segment.
  `default MemorySegment`
  SegmentAllocator.`allocateFrom(ValueLayout elementLayout, MemorySegment source, ValueLayout sourceElementLayout, long sourceOffset, long elementCount)`
  Returns a new memory segment initialized with the contents of the provided segment.
  `Optional<MemorySegment>`
  MemorySegment.`asOverlappingSlice(MemorySegment other)`
  Returns a slice of this segment that is the overlap between this and the provided segment.
  `static void`
  MemorySegment.`copy(MemorySegment srcSegment, long srcOffset, MemorySegment dstSegment, long dstOffset, long bytes)`
  Performs a bulk copy from source segment to destination segment.
  `static void`
  MemorySegment.`copy(MemorySegment srcSegment, ValueLayout srcElementLayout, long srcOffset, MemorySegment dstSegment, ValueLayout dstElementLayout, long dstOffset, long elementCount)`
  Performs a bulk copy from source segment to destination segment.
  `static void`
  MemorySegment.`copy(MemorySegment srcSegment, ValueLayout srcLayout, long srcOffset, Object dstArray, int dstIndex, int elementCount)`
  Copies a number of elements from a source memory segment to a destination array.
  `static void`
  MemorySegment.`copy(Object srcArray, int srcIndex, MemorySegment dstSegment, ValueLayout dstLayout, long dstOffset, int elementCount)`
  Copies a number of elements from a source array to a destination memory segment.
  `MemorySegment`
  MemorySegment.`copyFrom(MemorySegment src)`
  Performs a bulk copy from the given source segment to this segment.
  `MethodHandle`
  Linker.`downcallHandle(MemorySegment address, FunctionDescriptor function, Linker.Option... options)`
  Restricted.
  Creates a method handle that is used to call a foreign function with the given signature and address.
  `long`
  MemorySegment.`mismatch(MemorySegment other)`
  Finds and returns the offset, in bytes, of the first mismatch between this segment and the given other segment.
  `static long`
  MemorySegment.`mismatch(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.
  `static SegmentAllocator`
  SegmentAllocator.`prefixAllocator(MemorySegment segment)`
  Returns a segment allocator that responds to allocation requests by recycling a single segment.
  `void`
  MemorySegment.`set(AddressLayout layout, long offset, MemorySegment value)`
  Writes an address into this segment at the given offset, with the given layout.
  `void`
  MemorySegment.`setAtIndex(AddressLayout layout, long index, MemorySegment value)`
  Writes an address into this segment at the given index, scaled by the given layout size.
  `static SegmentAllocator`
  SegmentAllocator.`slicingAllocator(MemorySegment segment)`
  Returns a segment allocator that responds to allocation requests by returning consecutive slices obtained from the provided segment.
  Method parameters in java.lang.foreign with type arguments of type MemorySegment
  Modifier and Type
  Method
  Description
  `MemorySegment`
  MemorySegment.`reinterpret(long newSize, Arena arena, Consumer<MemorySegment> cleanup)`
  Restricted.
  Returns a new segment with the same address as this segment, but with the provided size and the provided arena's scope.
  `MemorySegment`
  MemorySegment.`reinterpret(Arena arena, Consumer<MemorySegment> cleanup)`
  Restricted.
  Returns a new memory segment with the same address and size as this segment, but with the provided arena's scope.

- ## Uses of MemorySegment in java.nio.channels

  Methods in java.nio.channels that return MemorySegment
  Modifier and Type
  Method
  Description
  `MemorySegment`
  FileChannel.`map(FileChannel.MapMode mode, long offset, long size, Arena arena)`
  Maps a region of this channel's file into a new mapped memory segment, with the given offset, size and arena.

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

  Methods in jdk.incubator.vector with parameters of type MemorySegment
  Modifier and Type
  Method
  Description
  `static ByteVector`
  ByteVector.`fromMemorySegment(VectorSpecies<Byte> species, MemorySegment ms, long offset, ByteOrder bo)`
  Loads a vector from a memory segment starting at an offset into the memory segment.
  `static ByteVector`
  ByteVector.`fromMemorySegment(VectorSpecies<Byte> species, MemorySegment ms, long offset, ByteOrder bo, VectorMask<Byte> m)`
  Loads a vector from a memory segment starting at an offset into the memory segment and using a mask.
  `static DoubleVector`
  DoubleVector.`fromMemorySegment(VectorSpecies<Double> species, MemorySegment ms, long offset, ByteOrder bo)`
  Loads a vector from a memory segment starting at an offset into the memory segment.
  `static DoubleVector`
  DoubleVector.`fromMemorySegment(VectorSpecies<Double> species, MemorySegment ms, long offset, ByteOrder bo, VectorMask<Double> m)`
  Loads a vector from a memory segment starting at an offset into the memory segment and using a mask.
  `static FloatVector`
  FloatVector.`fromMemorySegment(VectorSpecies<Float> species, MemorySegment ms, long offset, ByteOrder bo)`
  Loads a vector from a memory segment starting at an offset into the memory segment.
  `static FloatVector`
  FloatVector.`fromMemorySegment(VectorSpecies<Float> species, MemorySegment ms, long offset, ByteOrder bo, VectorMask<Float> m)`
  Loads a vector from a memory segment starting at an offset into the memory segment and using a mask.
  `static IntVector`
  IntVector.`fromMemorySegment(VectorSpecies<Integer> species, MemorySegment ms, long offset, ByteOrder bo)`
  Loads a vector from a memory segment starting at an offset into the memory segment.
  `static IntVector`
  IntVector.`fromMemorySegment(VectorSpecies<Integer> species, MemorySegment ms, long offset, ByteOrder bo, VectorMask<Integer> m)`
  Loads a vector from a memory segment starting at an offset into the memory segment and using a mask.
  `static LongVector`
  LongVector.`fromMemorySegment(VectorSpecies<Long> species, MemorySegment ms, long offset, ByteOrder bo)`
  Loads a vector from a memory segment starting at an offset into the memory segment.
  `static LongVector`
  LongVector.`fromMemorySegment(VectorSpecies<Long> species, MemorySegment ms, long offset, ByteOrder bo, VectorMask<Long> m)`
  Loads a vector from a memory segment starting at an offset into the memory segment and using a mask.
  `static ShortVector`
  ShortVector.`fromMemorySegment(VectorSpecies<Short> species, MemorySegment ms, long offset, ByteOrder bo)`
  Loads a vector from a memory segment starting at an offset into the memory segment.
  `static ShortVector`
  ShortVector.`fromMemorySegment(VectorSpecies<Short> species, MemorySegment ms, long offset, ByteOrder bo, VectorMask<Short> m)`
  Loads a vector from a memory segment starting at an offset into the memory segment and using a mask.
  `static final <E> VectorShuffle<E>`
  VectorShuffle.`fromMemorySegment(VectorSpecies<E> species, MemorySegment ms, long offset, ByteOrder bo)`
  Loads a shuffle from a memory segment starting at an offset into the memory segment.
  `Vector<E>`
  VectorSpecies.`fromMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Loads a vector of this species from a memory segment starting at an offset into the memory segment.
  `final void`
  ByteVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this vector into a memory segment starting at an offset using explicit byte order.
  `final void`
  ByteVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo, VectorMask<Byte> m)`
  Stores this vector into a memory segment starting at an offset using explicit byte order and a mask.
  `final void`
  DoubleVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this vector into a memory segment starting at an offset using explicit byte order.
  `final void`
  DoubleVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo, VectorMask<Double> m)`
  Stores this vector into a memory segment starting at an offset using explicit byte order and a mask.
  `final void`
  FloatVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this vector into a memory segment starting at an offset using explicit byte order.
  `final void`
  FloatVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo, VectorMask<Float> m)`
  Stores this vector into a memory segment starting at an offset using explicit byte order and a mask.
  `final void`
  IntVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this vector into a memory segment starting at an offset using explicit byte order.
  `final void`
  IntVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo, VectorMask<Integer> m)`
  Stores this vector into a memory segment starting at an offset using explicit byte order and a mask.
  `final void`
  LongVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this vector into a memory segment starting at an offset using explicit byte order.
  `final void`
  LongVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo, VectorMask<Long> m)`
  Stores this vector into a memory segment starting at an offset using explicit byte order and a mask.
  `final void`
  ShortVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this vector into a memory segment starting at an offset using explicit byte order.
  `final void`
  ShortVector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo, VectorMask<Short> m)`
  Stores this vector into a memory segment starting at an offset using explicit byte order and a mask.
  `abstract void`
  Vector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this vector into a memory segment starting at an offset using explicit byte order.
  `abstract void`
  Vector.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo, VectorMask<E> m)`
  Stores this vector into a memory segment starting at an offset using explicit byte order and a mask.
  `abstract void`
  VectorShuffle.`intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo)`
  Stores this shuffle into a memory segment starting at an offset using explicit byte order.