[foreign-memaccess] RFR 8227394: Add MemorySegment::asByteBuffer convenience method

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Jul 12 20:35:31 UTC 2019


On 12/07/2019 20:37, Jorn Vernee wrote:
> In almost all the the cases we already had access to the 
> MemorySegment, so we could just call asByteBuffer() directly on that. 
> The only case where we couldn't is in TestNative on line 114, since we 
> only have access to the MemoryAddress, not the segment. We have to use 
> the new `offset()` method to make a slice first, and then call 
> asByteBuffer() on the slice:
>
>     ByteBuffer bb = base.segment().slice(base.offset(), 
> (int)layout.byteSize()).asByteBuffer();
>
> We still end up using asByteBuffer() though, but it's not as much a 
> 1-to-1 change there. Probably should have just said "Updated tests to 
> use the new asByteBuffer()".

I've seen that - it's verbose - but all the others look better, so it 
seems like an improvement overall, and I like the cleanliness of the 1-1 
mapping between ranges/segment.

Looks good.

Maurizio

>
> Jorn
>
> On 2019-07-12 18:50, Maurizio Cimadamore wrote:
>> On 12/07/2019 16:26, Jorn Vernee wrote:
>>> * Updated tests to use the new asByteBuffer where possible (all but 
>>> one)
>>
>> Can you expand a bit on this?
>>
>> Thanks
>> Maurizio


More information about the panama-dev mailing list