[MLton] Is it safe to use an alternative malloc with Mlton programs?

Vesa Karvonen vesa.a.j.k at gmail.com
Tue Jan 20 04:03:53 PST 2009


On Tue, Jan 20, 2009 at 3:39 AM, Ville Tuulos <tuulos at gmail.com> wrote:
[...]
> Based on quick grepping of MLton's sources, it appears that malloc()
> is not used in many places - I assume that internal memory handling is
> done by mmap().

AFAIK that is the case.  MLton's GC uses mmap to allocate memory for
the ML heap.

> If this is the case, is it safe to link MLton / C code against TCMalloc?

I don't see how it could be unsafe, but I don't know MLton's GC
implementation very well.  The only potential problem that comes into
mind might be that if you incrementally allocate lots of memory from
both the "C heap" (allocated with malloc (whether glibc malloc or
TCMalloc)) and the ML heap, then, if/when a machine has a small
address space relative to the total amount of memory used, you might
fragment the address space so that MLton's GC fails to allocate (via
mmap) a sufficiently large contiguous block of memory for the ML heap
(when the heap needs to grow (or shrink)).

-Vesa Karvonen



More information about the MLton mailing list