Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8264594

Consider adding bulk array accessors to MemoryAccess

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • tbd
    • repo-panama
    • 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).

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

              Created:
              Updated:
              Resolved: