[foreign-preview] RFR: 8280460: MemorySegment::allocateNative should be tolerant of zero-sized allocation requests
Jorn Vernee
jvernee at openjdk.java.net
Tue Feb 22 14:05:00 UTC 2022
On Tue, 22 Feb 2022 13:05:57 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> This patch addresses the issues discussed here:
>
> https://mail.openjdk.java.net/pipermail/panama-dev/2022-January/016071.html
>
> And makes `MemorySegment::allocateNative` tolerand of zero-sized allocation requests. After evaluating a number of alternatives, I have decided to do what `ByteBuffer` also does, that is, always compute the size of the allocation as `max(size, 1L)`.
>
> This means that we always perform some allocation - which works better with alignment constraints (e.g. the address you get back is aligned as per request; this is a corner case, but makes the API more consistent).
>
> I've tweaked the javadoc to reflect that (and also added some javadoc to `SegmentAllocator` as well), and added a test for various kinds of native segments, created both safely and unsafely.
Marked as reviewed by jvernee (Committer).
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/650
More information about the panama-dev
mailing list