Package org.freedesktop.wayland.util
Class PointerArray
java.lang.Object
org.freedesktop.wayland.util.PointerArray
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MemorySegment
allocate
(long length, SegmentAllocator allocator) Allocates an array of pointers of the specified length.static MemorySegment
fromArray
(MemorySegment[] sources, SegmentAllocator session) Copies a Java array of MemorySegments into a native array of pointers.static <T> MemorySegment
fromStream
(Stream<T> stream, Function<T, MemorySegment> converter, SegmentAllocator allocator) Creates a native array of pointers from a stream of objects and a conversion function.static MemorySegment
getAtIndex
(MemorySegment array, long index) Gets a pointer value at the specified index in the array.static long
length
(MemorySegment array) Gets the length of the pointer array.static void
setAtIndex
(MemorySegment array, long index, MemorySegment value) Sets a pointer value at the specified index in the array.static MemorySegment[]
toArray
(MemorySegment array) Copies a native array of pointers into a Java array of MemorySegments.
-
Constructor Details
-
PointerArray
public PointerArray()
-
-
Method Details
-
allocate
Allocates an array of pointers of the specified length.- Parameters:
length
- The number of pointers in the array.allocator
- The Arena to use for allocation.- Returns:
- A MemorySegment representing the allocated array of pointers.
-
setAtIndex
Sets a pointer value at the specified index in the array.- Parameters:
array
- The MemorySegment representing the array of pointers.index
- The index at which to set the pointer.value
- The MemorySegment to set (representing a pointer).
-
getAtIndex
Gets a pointer value at the specified index in the array.- Parameters:
array
- The MemorySegment representing the array of pointers.index
- The index from which to get the pointer.- Returns:
- A MemorySegment representing the pointer at the specified index.
-
length
Gets the length of the pointer array.- Parameters:
array
- The MemorySegment representing the array of pointers.- Returns:
- The number of pointers in the array.
-
fromArray
Copies a Java array of MemorySegments into a native array of pointers.- Parameters:
sources
- The Java array of MemorySegments to copy.session
- The Arena to use for allocation.- Returns:
- A MemorySegment representing the native array of pointers.
-
toArray
Copies a native array of pointers into a Java array of MemorySegments.- Parameters:
array
- The MemorySegment representing the native array of pointers.- Returns:
- A Java array of MemorySegments.
-
fromStream
public static <T> MemorySegment fromStream(Stream<T> stream, Function<T, MemorySegment> converter, SegmentAllocator allocator) Creates a native array of pointers from a stream of objects and a conversion function.- Type Parameters:
T
- The type of objects in the stream.- Parameters:
stream
- The stream of objects to convert.converter
- A function that converts objects of type T to MemorySegments.allocator
- The Arena to use for allocation.- Returns:
- A MemorySegment representing the native array of pointers.
-