[MLton-user] ffi pointer lifetime

Stephen Weeks MLton-user@mlton.org
Mon, 12 May 2003 22:22:04 -0700


> Hello again, I'm writing a mixed language program. In the program there
> are values of type Word32.word. They are pointers to data structures in
> C-side which I allocated using malloc and other methods. Is it possible to
> instruct mlton call the destroy operation of a data structure when it
> collects the words out of the memory? 

We've just added support for finalization to MLton.  You can try it
out with our latest experimental release, 20030512, available at

	http://www.mlton.org/experimental

The relevant new function is

      	MLton.Finalize.finalize: 'a * (unit -> unit) -> unit

finalize (x, f) will run f () when x becomes unreachable.  The
finalizer runs after a garbage collection determines that x is
unreachable, which is done by keeping a weak pointer to x.  The
finalizer is treated like a signal handler, in that it runs
asynchronously in a separate thread with signals blocked and will
not run within a critical section.

Enjoy!


-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com

_______________________________________________
MLton-user mailing list
MLton-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-user