Different treatments of offsets in MemorySegment.set and copy methods.
Andrii Lomakin
lomakin.andrey at gmail.com
Thu Jun 22 07:03:09 UTC 2023
Hi team.
I am working with foreign API and noticed that offsets are treated
differently for the "set" and "copy" methods of MemorySegment in the case
of heap-based segments.
If I create a segment from let's say, byte[] and call "set(OfDouble, 0)" on
such a segment it doesn't take array offset into account during the
calculation of the applied offset value. So it processes this offset as is,
and I get an exception about address misalignment.
But if I pass offsets into the "copy" method, they are automatically
corrected.
Is it done by design?
IMHO, both methods should treat offsets uniformly, and that is not taking
into account that such treatments of offsets in "set" methods make it very
hard to work with heap-based segments.
P.S. I am using JDK 20.
--
Best regards,
Andrii Lomakin.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20230622/c39e57ec/attachment.htm>
More information about the panama-dev
mailing list