resource scopes and close actions

Michael Zucchi notzed at gmail.com
Wed Feb 2 01:34:28 UTC 2022


Morning,

I was hoping to use resource scopes to auto-cleanup native-allocated 
resources, but it looks like it's going to be a bit messy because 
segments get closed before their close actions are invoked.

Is this the intended behaviour or a side-effect of 'no particular order'?

For some api's it doesn't matter as they don't use api-allocated public 
structures (e.g. opencl) and the same approach is fine using 
MemoryAddress, but for others it's an issue (e.g. ffmpeg) where the 
obvious mapping is to use a segment and varhandles.

Probably as a workaround - if i want to have this feature at any rate 
because i'm not sure if it's a good idea yet - i'll just save a copy of 
the address before it's turned into a segment and pass that to any close 
function instead.

I've only really started looking at seeing how to 'scope' things 
'properly' but it feels a bit clumsy and sort of not worth it because it 
has to be worked around all the time either with hacks like this or 
resorting to simply using the global scope which effectively does nothing.

  Z




More information about the panama-dev mailing list