Span vs. MemorySegment

John Rose john.r.rose at oracle.com
Thu Aug 8 21:20:11 UTC 2019


On Aug 8, 2019, at 2:07 PM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
> 
> Thanks for the analysis. The info is correct - Spans are more sugary, segments are more low-level - but I think a bit more powerful where layouts meet dereference varhandles.
> 
> As for copy operations, we do have them - just not on MemorySegment - but on MemoryAddress:
> 
> http://cr.openjdk.java.net/~mcimadamore/panama/memaccess_javadoc/jdk/incubator/foreign/MemoryAddress.html#copy(jdk.incubator.foreign.MemoryAddress,jdk.incubator.foreign.MemoryAddress,long)

Oops, right, of course.  Anything that combines a Span with an index or offset translates to a MA which contains both.

> As for type-ful ness, it was a deliberate choice to make segments and addresses type-less, as when you work with heterogeneous buffers, having sticky type info is a downside rather than a plus - that was the lesson learned from the Pointer API. So, if you want low-level, ByteBuffer-like kind of access, type-less is the way to go IMHO (and, you can build typeful abstractions on top).

Yes; I fully agree that this is a fruitful approach.  We need to start with the bytes (and sometimes the bits!) if we are to support a wide variety of layouts, beyond simple arrays of some type T.

— John


More information about the panama-dev mailing list