# 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 memory segment with given size and default alignment constraints (1-byte aligned).
`MemorySegment`
SegmentAllocator.`allocate(long bytesSize, long bytesAlignment)`
Allocate a memory segment with given size and alignment constraints.
`default MemorySegment`
SegmentAllocator.`allocate(MemoryLayout layout)`
Allocate a memory segment with given layout.
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfAddress layout, Addressable value)`
Allocate a memory segment with given layout and initialize it with given address value (expressed as an `Addressable` instance).
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfByte layout, byte value)`
Allocate a memory segment with given layout and initialize it with given byte value.
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfChar layout, char value)`
Allocate a memory segment with given layout and initialize it with given char value.
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfDouble layout, double value)`
Allocate a memory segment with given layout and initialize it with given double value.
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfFloat layout, float value)`
Allocate a memory segment with given layout and initialize it with given float value.
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfInt layout, int value)`
Allocate a memory segment with given layout and initialize it with given int value.
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfLong layout, long value)`
Allocate a memory segment with given layout and initialize it with given long value.
`default MemorySegment`
SegmentAllocator.`allocate(ValueLayout.OfShort layout, short value)`
Allocate a memory segment with given layout and initialize it with given short value.
`default MemorySegment`
SegmentAllocator.`allocateArray(MemoryLayout elementLayout, long count)`
Allocate a memory segment with given element layout and size.
`default MemorySegment`
SegmentAllocator.`allocateArray(ValueLayout.OfByte elementLayout, byte[] array)`
Allocate a memory segment with given layout and initialize it with given byte array.
`default MemorySegment`
SegmentAllocator.`allocateArray(ValueLayout.OfChar elementLayout, char[] array)`
Allocate a memory segment with given layout and initialize it with given char array.
`default MemorySegment`
SegmentAllocator.`allocateArray(ValueLayout.OfDouble elementLayout, double[] array)`
Allocate a memory segment with given layout and initialize it with given double array.
`default MemorySegment`
SegmentAllocator.`allocateArray(ValueLayout.OfFloat elementLayout, float[] array)`
Allocate a memory segment with given layout and initialize it with given float array.
`default MemorySegment`
SegmentAllocator.`allocateArray(ValueLayout.OfInt elementLayout, int[] array)`
Allocate a memory segment with given layout and initialize it with given int array.
`default MemorySegment`
SegmentAllocator.`allocateArray(ValueLayout.OfLong elementLayout, long[] array)`
Allocate a memory segment with given layout and initialize it with given long array.
`default MemorySegment`
SegmentAllocator.`allocateArray(ValueLayout.OfShort elementLayout, short[] array)`
Allocate a memory segment with given layout and initialize it with given short array.
`static MemorySegment`
MemorySegment.`allocateNative(long bytesSize, long alignmentBytes, ResourceScope scope)`
Creates a new 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 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 native memory segment that models a newly allocated block of off-heap memory with given layout and resource scope.
`default MemorySegment`
SegmentAllocator.`allocateUtf8String(String str)`
Converts a Java string into a UTF-8 encoded, null-terminated C string, storing the result into a memory segment.
`MemorySegment`
MemorySegment.`asOverlappingSlice(MemorySegment other)`
Returns a slice of this segment that is the overlap between this and the provided segment.
`MemorySegment`
MemorySegment.`asReadOnly()`
Obtains a read-only view of this segment.
`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.`copyFrom(MemorySegment src)`
Performs a bulk copy from given source segment to this segment.
`MemorySegment`
MemorySegment.`fill(byte value)`
Fills a value into this memory segment.
`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.
`MemorySegment`
VaList.`nextVarg(GroupLayout layout, SegmentAllocator allocator)`
Reads the next value as a `MemorySegment`, and advances this variable argument list's position.
`static MemorySegment`
MemorySegment.`ofAddress(MemoryAddress address, long bytesSize, ResourceScope scope)`
Creates a new native memory segment with given size and resource scope, and whose base address is the given address.
`static MemorySegment`
MemorySegment.`ofArray(byte[] arr)`
Creates a new array memory segment that models the memory associated with a given heap-allocated byte array.
`static MemorySegment`
MemorySegment.`ofArray(char[] arr)`
Creates a new array memory segment that models the memory associated with a given heap-allocated char array.
`static MemorySegment`
MemorySegment.`ofArray(double[] arr)`
Creates a new array memory segment that models the memory associated with a given heap-allocated double array.
`static MemorySegment`
MemorySegment.`ofArray(float[] arr)`
Creates a new array memory segment that models the memory associated with a given heap-allocated float array.
`static MemorySegment`
MemorySegment.`ofArray(int[] arr)`
Creates a new array memory segment that models the memory associated with a given heap-allocated int array.
`static MemorySegment`
MemorySegment.`ofArray(long[] arr)`
Creates a new array memory segment that models the memory associated with a given heap-allocated long array.
`static MemorySegment`
MemorySegment.`ofArray(short[] arr)`
Creates a new array memory segment that models the memory associated with a given heap-allocated short array.
`static MemorySegment`
MemorySegment.`ofByteBuffer(ByteBuffer bb)`
Creates a new buffer memory segment that models the memory associated with the given byte buffer.
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
`VaList.Builder`
VaList.Builder.`addVarg(GroupLayout layout, MemorySegment value)`
Writes a `MemorySegment` value, with given layout, to the variable argument list being constructed.
`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(Object srcArray, int srcIndex, MemorySegment dstSegment, ValueLayout dstLayout, long dstOffset, int elementCount)`
Copies a number of elements from a source array to a destination segment, starting at a given array index, and a given segment offset (expressed in bytes), using the given destination element layout.
`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 srcLayout, long srcOffset, Object dstArray, int dstIndex, int elementCount)`
Copies a number of elements from a source segment to a destination array, starting at a given segment offset (expressed in bytes), and a given array index, using the given source element layout.
`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.
`default MemorySegment`
MemorySegment.`copyFrom(MemorySegment src)`
Performs a bulk copy from given source segment to this segment.
`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.`prefixAllocator(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), hence the name prefix allocator.
`long`
MemorySegment.`segmentOffset(MemorySegment other)`
Returns the offset, in bytes, of the provided segment, relative to this segment.