openImplicit
    Maurizio Cimadamore 
    maurizio.cimadamore at oracle.com
       
    Sat Apr 22 00:24:51 UTC 2023
    
    
  
On 21/04/2023 22:16, Michael Hall wrote:
> I may of misunderstood implicit. I thought that gave you a garbage collection managed memory segment. So heap? I guess I was wrong.
With implicit/auto you can create a _native_ memory segment whose 
lifetime is managed automatically by the garbage collector. So, in a 
way, you're right that it works like a Java array, in the sense that 
when the segment becomes unreachable, its backing off-heap memory can be 
reclaimed (at some unspecified point). This is also the way in which the 
backing native memory of a direct byte buffer is managed.
You can also obtain segments that are backed by on-heap memory, by 
wrapping a segment around a Java array. E.g. doing 
MemorySegment.ofArray(new int[200]). If you do that, the resulting 
segment will have a non-empty array.
Since in your case you are working with off-heap memory (otherwise you 
wouldn't be able to exchange data with native functions), it is normal 
for the segment backing array to be null/empty, given that the memory 
segment is backed by a region of memory that resides off the Java heap.
I hope this helps.
Maurizio
    
    
More information about the panama-dev
mailing list