java 14 and JEP 370: Foreign-Memory Access API-- Array Of Bytes.
Ahmed Hamdallah
ahmdprog at gmail.com
Wed Mar 25 16:56:07 UTC 2020
Thank you Maurizio & Henry,
Yes I realized the solution to copy bulk array using MemoryAddress:copy.
It also works via versa. Read + write.
MemoryAddress.copy(MemorySegment.ofArray(bytesArrayString).baseAddress(), address, bytesArrayString.length); // write
MemoryAddress.copy(address, MemorySegment.ofArray(bytesArrayString2).baseAddress(), bytesArrayString.length); // read
Regards,
On 25/03/2020, 8:33 PM, "panama-dev on behalf of Maurizio Cimadamore" <panama-dev-bounces at openjdk.java.net on behalf of maurizio.cimadamore at oracle.com> wrote:
Yeah - I now realize I did not reply to the original question.
The way to go to do bulk access is to use the MemoryAddress::copy API,
as shown in the email from Henry.
That is:
1) create an on-heap segment backed by a byte[]
2) copy portions of the off-heap segment into the on-heap segment using
MemoryAddress:copy
Maurizio
On 25/03/2020 15:58, Ty Young wrote:
> They seem to want a method that accepts an array of bytes(byte[])
> which is then put into memory and then be able to get it back without
> accessing individual offset locations or using ByteBuffer.
>
>
> There is no such thing for setting AFAIK. The MemorySegment.ofArray()
> methods just create a MemorySegment that can hold an array of the
> given array's size AFAIK.
>
>
> There is a method for getting the array in bulk though:
> <MemorySegment>.toByteArray().
>
>
More information about the panama-dev
mailing list