[MLton] Callback functions: how?
Henry Cejtin
henry.cejtin at sbcglobal.net
Thu Feb 15 10:54:14 PST 2007
Yes, the connection id ends up just being the word which is the key in the
hash table, so you can remove the entry.
Note, if the time of the hash lookup is really to expensive (and it is really
pretty cheap because the hash is delivered as the void * argument, so you
just and it with a mask and then use that as a lookup into a list), then you
could use a trick like this: you use an array instead of a hash table, as
discussed, but the void * argument isn't an integer but a pointer to an
integer (pointing into the C heap). This way you can re-number the integers
pointed to when the array becomes too sparsely occupied. It costs you one
level of indirection (to get the int) but is safe for space.
In MLton, a `closure' is just an element of a datatype, with the choice
corresponding to the code part of the closure and the rest being the closed
over variables. My guess is that this pretty much always ends up getting
boxed.
Re _export, note that MLton never ever puts any code in the heap. As above,
the closure is just an element of the datatype. The choice of the datatype
tells you which static piece of code to use. Thanks to whole program
compilation, all those bits of code are known and fixed at compile time.
Only the closed over variables cause a potentially unbounded number of cases,
and those are just kept in the data carried by that choice.
More information about the MLton
mailing list