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

Consider adding bulk array accessors to MemoryAccess

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: repo-panama
    • Fix Version/s: tbd_major
    • Component/s: tools

      Description

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated: