-
Enhancement
-
Resolution: Fixed
-
P3
-
repo-panama
Copying contents of a segments into an array (or viceversa) is currently convoluted as users have to convert the array into a segment, and then slice source/dest segment and perform a bulk copy using copyFrom.
We could add static helpers on MemoryAccess, like these:
@ForceInline
public static void getToIntArray(MemorySegment segment, long srcIndex, int[] arr, int dstIndex, int nElems) {
MemorySegment srcSegSlice = segment.asSlice(srcIndex << 2, nElems << 2);
MemorySegment dstSeg = MemorySegment.ofArray(arr);
MemorySegment dstSegSlice = dstSeg.asSlice(dstIndex << 2, nElems << 2);
dstSegSlice.copyFrom(srcSegSlice);
}
Which will greatly simplify the task. The dual of this could be called "setFromIntArray".
Note that maybe we'd want AtIndex/AtOffset variants (to specify segment position in logical index vs. raw offset), plus endianness (e.g. to do a "swappy" bulk copy), which makes for 4 overloads per carrier type, per accessor type (get/set).
We could add static helpers on MemoryAccess, like these:
@ForceInline
public static void getToIntArray(MemorySegment segment, long srcIndex, int[] arr, int dstIndex, int nElems) {
MemorySegment srcSegSlice = segment.asSlice(srcIndex << 2, nElems << 2);
MemorySegment dstSeg = MemorySegment.ofArray(arr);
MemorySegment dstSegSlice = dstSeg.asSlice(dstIndex << 2, nElems << 2);
dstSegSlice.copyFrom(srcSegSlice);
}
Which will greatly simplify the task. The dual of this could be called "setFromIntArray".
Note that maybe we'd want AtIndex/AtOffset variants (to specify segment position in logical index vs. raw offset), plus endianness (e.g. to do a "swappy" bulk copy), which makes for 4 overloads per carrier type, per accessor type (get/set).