I am wondering if it is possible to create a finalise method for OCaml records? I am creating a GPU database and I am using OCaml for building the DSL to query and manipulate GPU data, and I need a way to free GPU memory when they are eligible for GC (not referenced anymore).
I have creating a binding to my C-based GPU api to allow to malloc, free and manipulate GPU data but I am looking at solutions to free GPU memory when it is not referenced by variables anymore in the toplevel.
let bids = (**a 1-dim GPU array*) and asks = (**another 1-dim GPU array*) in
let spread = asks - bids
In this example, I would need to free up the GPU memory for the bids and asks vector residing in GPU memory. I guess I need to write my own language?
What you need is probably custom blocks, since your data is not pure Caml:
http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual033.html
19.9 Advanced topic: custom blocks
Blocks with tag Custom_tag contain both arbitrary user data and a pointer to a C struct, with type struct custom_operations, that associates user-provided finalization, comparison, hashing, serialization and deserialization functions to this block.
You can attach your C finalization functions to custom blocks. They are called when the block is GCed in OCaml world.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With