@@ -39,7 +39,35 @@ public static MemoryLayout booleanLayout() {
3939 return ValueLayout .JAVA_BOOLEAN ;
4040 }
4141
42- public static MemoryLayout sequenceLayout (int capacity ) {
42+ public static MemoryLayout intArrayLayout (int length ) {
43+ return MemoryLayout .sequenceLayout (length , ValueLayout .JAVA_INT );
44+ }
45+
46+ public static MemoryLayout longArrayLayout (int length ) {
47+ return MemoryLayout .sequenceLayout (length , ValueLayout .JAVA_LONG );
48+ }
49+
50+ public static MemoryLayout floatArrayLayout (int length ) {
51+ return MemoryLayout .sequenceLayout (length , ValueLayout .JAVA_FLOAT );
52+ }
53+
54+ public static MemoryLayout doubleArrayLayout (int length ) {
55+ return MemoryLayout .sequenceLayout (length , ValueLayout .JAVA_DOUBLE );
56+ }
57+
58+ public static MemoryLayout byteArrayLayout (int length ) {
59+ return MemoryLayout .sequenceLayout (length , ValueLayout .JAVA_BYTE );
60+ }
61+
62+ public static MemoryLayout shortArrayLayout (int length ) {
63+ return MemoryLayout .sequenceLayout (length , ValueLayout .JAVA_SHORT );
64+ }
65+
66+ public static MemoryLayout booleanArrayLayout (int length ) {
67+ return MemoryLayout .sequenceLayout (length , ValueLayout .JAVA_BOOLEAN );
68+ }
69+
70+ public static MemoryLayout stringLayout (int capacity ) {
4371 return MemoryLayout .sequenceLayout (capacity , ValueLayout .JAVA_BYTE );
4472 }
4573
@@ -67,8 +95,35 @@ public static void set(MemorySegment segment, long offset, long value) {
6795 segment .set (ValueLayout .JAVA_LONG , offset , value );
6896 }
6997
70- public static void set (MemorySegment segment , long offset , boolean value ) {
71- segment .set (ValueLayout .JAVA_BOOLEAN , offset , value );
98+ public static void set (MemorySegment segment , long offset , int [] value , int capacity ) {
99+ MemorySegment .copy (value , 0 , segment , ValueLayout .JAVA_INT , offset , capacity );
100+ }
101+
102+ public static void set (MemorySegment segment , long offset , long [] value , int capacity ) {
103+ MemorySegment .copy (value , 0 , segment , ValueLayout .JAVA_LONG , offset , capacity );
104+ }
105+
106+ public static void set (MemorySegment segment , long offset , float [] value , int capacity ) {
107+ MemorySegment .copy (value , 0 , segment , ValueLayout .JAVA_FLOAT , offset , capacity );
108+ }
109+
110+ public static void set (MemorySegment segment , long offset , double [] value , int capacity ) {
111+ MemorySegment .copy (value , 0 , segment , ValueLayout .JAVA_DOUBLE , offset , capacity );
112+ }
113+
114+ public static void set (MemorySegment segment , long offset , byte [] value , int capacity ) {
115+ MemorySegment .copy (value , 0 , segment , ValueLayout .JAVA_BYTE , offset , capacity );
116+ }
117+
118+ public static void set (MemorySegment segment , long offset , short [] value , int capacity ) {
119+ MemorySegment .copy (value , 0 , segment , ValueLayout .JAVA_SHORT , offset , capacity );
120+ }
121+
122+ public static void set (MemorySegment segment , long offset , boolean [] value , int capacity ) {
123+ int len = Math .min (value .length , capacity );
124+ for (int i = 0 ; i < len ; i ++) {
125+ segment .set (ValueLayout .JAVA_BYTE , offset + i , (byte ) (value [i ] ? 1 : 0 ));
126+ }
72127 }
73128
74129 public static void set (MemorySegment segment , long offset , String value , int capacity ) {
@@ -111,6 +166,39 @@ public static boolean getBoolean(MemorySegment segment, long offset) {
111166 return segment .get (ValueLayout .JAVA_BOOLEAN , offset );
112167 }
113168
169+ public static int [] getIntArray (MemorySegment segment , long offset , int length ) {
170+ return segment .asSlice (offset , length * ValueLayout .JAVA_INT .byteSize ()).toArray (ValueLayout .JAVA_INT );
171+ }
172+
173+ public static long [] getLongArray (MemorySegment segment , long offset , int length ) {
174+ return segment .asSlice (offset , length * ValueLayout .JAVA_LONG .byteSize ()).toArray (ValueLayout .JAVA_LONG );
175+ }
176+
177+ public static float [] getFloatArray (MemorySegment segment , long offset , int length ) {
178+ return segment .asSlice (offset , length * ValueLayout .JAVA_FLOAT .byteSize ()).toArray (ValueLayout .JAVA_FLOAT );
179+ }
180+
181+ public static double [] getDoubleArray (MemorySegment segment , long offset , int length ) {
182+ return segment .asSlice (offset , length * ValueLayout .JAVA_DOUBLE .byteSize ()).toArray (ValueLayout .JAVA_DOUBLE );
183+ }
184+
185+ public static byte [] getByteArray (MemorySegment segment , long offset , int length ) {
186+ return segment .asSlice (offset , length * ValueLayout .JAVA_BYTE .byteSize ()).toArray (ValueLayout .JAVA_BYTE );
187+ }
188+
189+ public static short [] getShortArray (MemorySegment segment , long offset , int length ) {
190+ return segment .asSlice (offset , length * ValueLayout .JAVA_SHORT .byteSize ()).toArray (ValueLayout .JAVA_SHORT );
191+ }
192+
193+ public static boolean [] getBooleanArray (MemorySegment segment , long offset , int length ) {
194+ boolean [] result = new boolean [length ];
195+ for (int i = 0 ; i < length ; i ++) {
196+ byte value = segment .get (ValueLayout .JAVA_BYTE , offset + i );
197+ result [i ] = value != 0 ;
198+ }
199+ return result ;
200+ }
201+
114202 public static String getFixedString (MemorySegment segment , long offset , int capacity ) {
115203 return segment .asSlice (offset , capacity ).getString (0 );
116204 }
0 commit comments