[MLton-user] Calling into SML from C

Zach Anderson zra at cs.berkeley.edu
Fri Apr 13 18:09:40 PDT 2007


Vesa Karvonen wrote:
> On 4/12/07, Zach Anderson <zra at cs.berkeley.edu> wrote:
>> Is there an easy way to call into SML code from a program with a C
>> main()?

> Not at the moment AFAIK.  However, it is easy to make an application
> with MLton that calls C code (library) which then calls SML code.  For
> example, you can have an application with an event loop written in C
> that calls SML callbacks.  The MLton FFI supports calling from C to SML
> (http://mlton.org/CallingFromCToSML).

I've essentially decided to go with this solution. I'm instrumenting 
legacy C code with calls into SML code, so I just have my SML code call 
the C main, etc.

However, I've run into a problem. At the moment all that the SML calls 
do is take a bunch of ints(I've also tried words), and do nothing but 
return unit. This causes lots and lots of memory to be allocated, and 
lots of time to be spent in the GC. Are the integers being boxed? What 
integral type should I use so that the integers I pass to the SML calls 
aren't boxed? Is that possible?

Thanks,
Zach



More information about the MLton-user mailing list