Consider adding bulk array accessors to MemoryAccess

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P3
    • tbd
    • Affects Version/s: repo-panama
    • Component/s: tools

      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).

            Assignee:
            Unassigned
            Reporter:
            Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: