I want to implement a datastructure in native memory using the Foreign Memory Access API of Project Panama.
In order to do that I need an underlying Object array (Object[]
) for the entries.
In all the examples for the Foreign Memory Access API, MemorySegments are only used to store and retrieve primitives like so:
//I would like to use Object here instead of int
ResourceScope scope = ResourceScope.newConfinedScope();
SequenceLayout layout = MemoryLayout.sequenceLayout(100, MemoryLayouts.JAVA_INT);
VarHandle intHandle = seq.varHandle(int.class, sequenceElement());
MemorySegment segment = MemorySegment.allocateNative(layout, scope);
Is there a way to store non primitives in a MemorySegment (e.g. Object)? And if that is the case how can I dereference that MemorySegment using a VarHandle, when VarHandles only support primitive carriers?