Using Layouts on heap - JDK18

leerho leerho at gmail.com
Fri Jun 3 16:56:18 UTC 2022


Hi,
It is straightforward to create a native MemorySegment governed by a
layout, but I can't see a way to create a heap segment governed by a layout
(without a copy).  We need to be able to read and write to structs on-heap
as well as off-heap.  Being able to overlay a Layout on a segment derived
from a ByteBuffer or from a mapped file would also be useful. Perhaps these
could be implemented via a slice?

What I would like to see is something like:

*MemorySegment *allocate*(MemoryLayout layout);  //base resource is byte[]*

OR

> *MemorySegment *asSlice*(long offset, MemoryLayout layout)*


The second could be applied to any base resource, not just off-heap.

Am I missing something?

Cheers,
Lee.


More information about the panama-dev mailing list