MemorySegment off-heap usage and GC

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Sep 18 17:05:34 UTC 2024


On 18/09/2024 17:58, Maurizio Cimadamore wrote:
> As to go from byte[] to big memory segment, you can copy your byte[] 
> into a memory segment (at desired offset) w/o need to make a new 
> memory segment, or slice, using this:
>
> https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/foreign/MemorySegment.html#copy(java.lang.Object,int,java.lang.foreign.MemorySegment,java.lang.foreign.ValueLayout,long,int)

Note though: even if you eliminate intermediate segment creation - you 
are still left with a bulk copy (and some other stuff) to do.

E.g. this method:

https://github.com/sirixdb/sirix/blob/1aaafd13693c0cf7e073d400766525eed7a24ad6/bundles/sirix-core/src/main/java/io/sirix/page/KeyValueLeafPage.java#L394

Simply had no equivalent in the old code (used to be an O(1) assignment).

I don't know how "hot" is this method - maybe this is a cold path, and 
you don't care if it got 10x slower - but I was mostly drawing your 
attention that you went from O(1) to O(n) there.

Maurizio



More information about the panama-dev mailing list