[MLton] Representation of strings in the FFI

Stephen Weeks MLton@mlton.org
Wed, 27 Apr 2005 16:06:21 -0700

> Suppose I at the C level want to produce an MLton array and then
> call bar with it. Is GC_arrayAllocate the best way of allocating the
> array?

No.  If you want to allocate an array from the C side, the easiest and
safest way is to export a function from the ML side that does the
allocation you want.  For example, the following will export a
function that creates an int array with elements initialized to the
specified value.

  val _ = _export "alloc": int * int -> int array; 

Matthew's provisos about the GC moving stuff behind your back still
apply, but at least you don't need any special understanding of GC
routines or object layout.