[MLton] Callback functions: how?

Vesa Karvonen vesa.karvonen at cs.helsinki.fi
Wed Feb 14 15:08:38 PST 2007


Quoting "Wesley W. Terpstra" <wesley at terpstra.ca>:
> Vesa Karvonen wrote:
> > Basically, there is a single exported ML callback function and a
> > callback cache for each imported C function that takes callbacks.
> > The key generated by the cache is given to the C side as the
> > context pointer (uarg in your snippet).
> This sounds pretty much the same as my solution, except that my hash  
> function is (fn x => x) and I don't need a collision policy.

Yes.  I also considered the same free list scheme that you are using.
It has one deficiency with respect to scaling.  Namely, if the array
becomes large at some point (lots of callbacks registered), it may not
be possible to shrink it (after most of those callbacks are
unregistered).  The free list scheme is fine if there is a (small)
upper bound on the number of active simultaneous callbacks for each
imported C function.  Otherwise it may consume arbitrary amounts of
memory without doing useful work.

-Vesa Karvonen



More information about the MLton mailing list