Uses of Interface
jdk.incubator.foreign.MemorySegment
Package
Description
Classes to support low-level and efficient foreign memory/function access, directly from Java.
-
Uses of MemorySegment in jdk.incubator.foreign
Modifier and TypeMethodDescriptiondefault MemorySegment
NativeScope.allocate(long bytesSize)
Allocate a block of memory in this native scope with given size.NativeScope.allocate(long bytesSize, long bytesAlignment)
Allocate a block of memory in this native scope with given size and alignment constraint.default MemorySegment
NativeScope.allocate(MemoryLayout layout)
Allocate a block of memory in this native scope with given layout.default MemorySegment
NativeScope.allocate(ValueLayout layout, byte value)
Allocate a block of memory in this native scope with given layout and initialize it with given byte value.default MemorySegment
NativeScope.allocate(ValueLayout layout, char value)
Allocate a block of memory in this native scope with given layout and initialize it with given char value.default MemorySegment
NativeScope.allocate(ValueLayout layout, double value)
Allocate a block of memory in this native scope with given layout and initialize it with given double value.default MemorySegment
NativeScope.allocate(ValueLayout layout, float value)
Allocate a block of memory in this native scope with given layout and initialize it with given float value.default MemorySegment
NativeScope.allocate(ValueLayout layout, int value)
Allocate a block of memory in this native scope with given layout and initialize it with given int value.default MemorySegment
NativeScope.allocate(ValueLayout layout, long value)
Allocate a block of memory in this native scope with given layout and initialize it with given long value.default MemorySegment
NativeScope.allocate(ValueLayout layout, short value)
Allocate a block of memory in this native scope with given layout and initialize it with given short value.default MemorySegment
NativeScope.allocate(ValueLayout layout, Addressable value)
Allocate a block of memory in this native scope with given layout and initialize it with given address value (expressed as anAddressable
instance).default MemorySegment
NativeScope.allocateArray(MemoryLayout elementLayout, long count)
Allocate a block of memory corresponding to an array with given element layout and size.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, byte[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given byte array.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, char[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given char array.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, double[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given double array.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, float[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given float array.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, int[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given int array.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, long[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given long array.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, short[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given short array.default MemorySegment
NativeScope.allocateArray(ValueLayout elementLayout, Addressable[] array)
Allocate a block of memory in this native scope with given layout and initialize it with given address array.static MemorySegment
MemorySegment.allocateNative(long bytesSize)
Creates a new confined native memory segment that models a newly allocated block of off-heap memory with given size (in bytes).static MemorySegment
MemorySegment.allocateNative(long bytesSize, long alignmentBytes)
Creates a new confined native memory segment that models a newly allocated block of off-heap memory with given size and alignment constraint (in bytes).static MemorySegment
MemorySegment.allocateNative(MemoryLayout layout)
Creates a new confined native memory segment that models a newly allocated block of off-heap memory with given layout.default MemorySegment
MemoryAddress.asSegmentRestricted(long bytesSize)
Returns a new confined native memory segment with given size, and whose base address is this address; the returned segment has its own temporal bounds, and can therefore be closed.MemoryAddress.asSegmentRestricted(long bytesSize, Runnable cleanupAction, Object attachment)
Returns a new confined native memory segment with given size, and whose base address is this address; the returned segment has its own temporal bounds, and can therefore be closed.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.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 (seeMemoryAddress.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.fill(byte value)
Fills a value into this memory segment.Obtains a new confined memory segment backed by the same underlying memory region as this segment.MemorySegment.handoff(NativeScope nativeScope)
Obtains a new confined memory segment backed by the same underlying memory region as this segment, but whose temporal bounds are controlled by the providedNativeScope
instance.static MemorySegment
MemorySegment.mapFile(Path path, long bytesOffset, long bytesSize, FileChannel.MapMode mapMode)
Creates a new confined 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
MemorySegment.ofNativeRestricted()
Returns a shared native memory segment whose base address isMemoryAddress.NULL
and whose size isLong.MAX_VALUE
.MemorySegment.registerCleaner(Cleaner cleaner)
Register this memory segment instance against aCleaner
object, by returning a new memory segment backed by the same underlying memory region as this segment.MemorySegment.share()
Obtains a new shared memory segment backed by the same underlying memory region as this segment.static MemorySegment
Converts a Java string into a null-terminated C string, using the platform's default charset, storing the result into a new native memory segment.static MemorySegment
Converts a Java string into a null-terminated C string, using the givencharset
, storing the result into a new native memory segment.static MemorySegment
CLinker.toCString(String str, Charset charset, NativeScope scope)
Converts a Java string into a null-terminated C string, using the givencharset
, storing the result into a new native memory segment native memory segment allocated using the provided scope.static MemorySegment
CLinker.toCString(String str, NativeScope scope)
Converts a Java string into a null-terminated C string, using the platform's default charset, storing the result into a native memory segment allocated using the provided scope.CLinker.upcallStub(MethodHandle target, FunctionDescriptor function)
Allocates a native segment whose base address (seeaddress()
) can be passed to other foreign functions (as a function pointer); calling such a function pointer from native code will result in the execution of the provided method handle.CLinker.VaList.vargAsSegment(MemoryLayout layout)
Reads the next value as aMemorySegment
, and advances this va list's position.CLinker.VaList.vargAsSegment(MemoryLayout layout, NativeScope scope)
Reads the next value as aMemorySegment
, and advances this va list's position.MemorySegment.withAccessModes(int accessModes)
Obtains a segment view with specific access modes.Modifier and TypeMethodDescriptionMemorySegment.spliterator(SequenceLayout layout)
Returns a spliterator for this memory segment.Modifier and TypeMethodDescriptionvoid
MemorySegment.copyFrom(MemorySegment src)
Performs a bulk copy from given source segment to this segment.static void
MappedMemorySegments.force(MemorySegment segment)
Forces any changes made to the contents of the given segment to be written to the storage device described by the mapped segment's file descriptor.static MemoryAddress
MemoryAccess.getAddress(MemorySegment segment)
Reads a memory address from given segment, with byte order set toByteOrder.nativeOrder()
.static MemoryAddress
MemoryAccess.getAddressAtIndex(MemorySegment segment, long index)
Reads a memory address from given segment and element index, with byte order set toByteOrder.nativeOrder()
.static MemoryAddress
MemoryAccess.getAddressAtOffset(MemorySegment segment, long offset)
Reads a memory address from given segment and offset, with byte order set toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.nativeOrder()
.static short
MemoryAccess.getShortAtOffset(MemorySegment segment, long offset, ByteOrder order)
Reads a short from given segment and offset with given byte order.static boolean
MappedMemorySegments.isLoaded(MemorySegment segment)
Tells whether or not the contents of the given segment is resident in physical memory.static void
MappedMemorySegments.load(MemorySegment segment)
Loads the contents of the given segment into physical memory.long
MemorySegment.mismatch(MemorySegment other)
Finds and returns the offset, in bytes, of the first mismatch between this segment and a given other segment.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 toByteOrder.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 toByteOrder.nativeOrder()
.static void
MemoryAccess.setAddressAtOffset(MemorySegment segment, long offset, Addressable value)
Writes a memory address at given segment and offset, with byte order set toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 toByteOrder.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 null-terminated C string stored at given address into a Java string, using the platform's default charset.static String
CLinker.toJavaString(MemorySegment addr, Charset charset)
Converts a null-terminated C string stored at given address into a Java string, using the givencharset
.static void
MappedMemorySegments.unload(MemorySegment segment)
Unloads the contents of the given segment from physical memory.CLinker.VaList.Builder.vargFromSegment(GroupLayout layout, MemorySegment value)
Adds a native value represented as aMemorySegment
to the Cva_list
being constructed.