Question: ByteBuffer vs MemorySegment for binary (de)serializiation and in-memory buffer pool

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Sep 1 20:52:36 UTC 2022


On 01/09/2022 19:26, Gavin Ray wrote:
> I think this is where my impression of verbosity is coming from, in 
> [1] I've linked a gist of ByteBuffer vs MemorySegment implementation 
> of a page header struct,
> and it's the layout/varhandles that are the only difference, really.
>
Ok, I see what you mean, of course; thanks for the Gist.

In this case I think the instance accessor we added on MemorySegment 
will bring the code more or less to the same shape as what it used to be 
with the ByteBuffer API.

Using var handles is very useful when you want to access elements (e.g. 
structs inside other structs inside arrays) as it takes all the offset 
computation out of the way.

If you're happy enough with hardwired offsets (and I agree that in this 
case things might be good enough), then there's nothing wrong with using 
the ready-made accessor methods.

Maurizio



More information about the panama-dev mailing list