[foreign-abi] RFR: 8253823: Investigate ways to make handoff-like operation more explicit [v6]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu Oct 1 10:50:37 UTC 2020
On Wed, 30 Sep 2020 18:52:14 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
> This is indeed simpler (esp. also for implementation of the clean up actions).
>
> I am not entirely convinced with clean up action being only associated with unchecked segment creation. For example the
> [BLIS object API](https://github.com/flame/blis/blob/master/docs/BLISObjectAPI.md) may be used to create
> (`bli_obj_create`) and free (`bli_obj_free`) the allocated region of memory representing a matrix with elements of a
> certain type. The BLIS `obj_t` would be allocated separately as a segment and it may be useful to attach a cleanup
> action to that segment to free the region using the native method call.
I understand the concern - however, the cleanup action associated to an unchecked memory segment has always been more
about supporting low-level pieces of machinery, such as custom memory allocators, which might want to allocate memory
in C/C++ and then exposing said memory using a plain MemorySegment.
For more convoluted idioms such as the one you describe, where the library mandates some setup/destroy actions, I feel
that adding an explicit construct (which might also be auto closeable) _wrapping_ a segment, might be a better way to
go, rather than exposing segment _as is_.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/361
More information about the panama-dev
mailing list