Say I have some CArray, and I want to pass it’s start pointer to some asynchronous C function, and I want to make sure my CArray persists until async function completes?
RWO suggests the following: “achieve this via a global array of values on the OCaml side that would keep them live until they’re no longer needed”, but it lacks an example on how this can be done, probably with some
Obj.magic to put various stuff into one global array? And how can one remove certain item from that array?
So far I’m using
Ctypes.Root.create my_value, and save the integer value where appropriate so that I can later do
Ctypes.Root.release my_saved_root, but I have suspicion that this is sort of abuse of ctypes roots, which are intended for passing OCaml values to C layer via those integer values? Yet they also exist to protect the values from premature gargabe collection, so does not sound too awful?
I found this email which describes what are Ctypes roots for: http://lists.ocaml.org/pipermail/ctypes/2015-September/000191.html
Any hints at how this problem is best solved are appreciated!