[foreign-memaccess+abi] RFR: 8270376: Finalize API for memory copy [v9]
Paul Sandoz
psandoz at openjdk.java.net
Fri Aug 6 18:46:53 UTC 2021
On Fri, 6 Aug 2021 18:18:35 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> > Re: `MemorySegment.toXArray`, yes good point. I think we could remove these. They are a bit like the `Arrays.copyOf/Range` methods. Not suggesting we such methods.
>
> I'm less sure about this now - on the one hand these are clearly redundant. On the other hand, there is a symmetry between MemorySegment::ofArray(XYZ[]) and MemorySegment::toXYZArray().
>
Although a key difference is `ofArray` is a factory method creating a view over the memory region covered by the primitive array, not a copy, so i would argue its not quite symmetric. Might as well do `intArray..clone()` rather than `MemorySegment.ofArray(intArray).toIntArray()`
> Another option would be to just expose a `toByteArray`, e.g. just expose a basic byte view of the segment (after all a segment is just a bag of bytes), which would be consistent with the decision of only exposing `asByteBuffer` (although it's easier to go from, say, a ByteBuffer to an IntBuffer than it is to go from a byte array to an int array).
Yeah, i think that would simplify, giving us choices to expand copying utilities in `MemoryAccess` if need be.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/568
More information about the panama-dev
mailing list