PREV UP NEXT StackThreads/MP: version 0.77 User's Guide

4.3.1: Changing the Underlying Allocator

        #include <st_mm.h>
@        void * MM_ALLOC(sz);
@        void MM_FREE(ptr);
@        void MM_ZERO_CLEAR(ptr, sz);
@        void MM_GC_POINT();
@        void MM_SETUP(fd);

They are macros whose behavior change according to the following parameter.

        #define UNDERLYING_MM ...

It chooses the basic memory allocator and can be selected from the following values:

        UNDERLYING_MM_SGC_AUTO_GC
@        UNDERLYING_MM_SGC_EXP_GC
@        UNDERLYING_MM_SGC_EXP_FREE
@        UNDERLYING_MM_MALLOC

UNDERLYING_MM_SGC_AUTO_GC uses SGC and relies on its automatic memory management. UNDERLYING_MM_SGC_EXP_GC uses SGC, but triggers GC only when explicitly requested by MM_GC_POINT(). UNDERLYING_MM_SGC_EXP_FREE uses SGC, but never frees objects by GC. Finally, UNDERLYING_MM_MALLOC uses the system's default malloc.

MM_ALLOC calls the appropriate allocator. MM_FREE(ptr) frees object pointed to by ptr when UNDERLYING_MM_SGC_EXP_FREE or UNDERLYING_MM_MALLOC is given, and otherwise has no effects. MM_ZERO_CLEAR(ptr, sz) clears a block of sz bytes from ptr, only when MM_ALLOC does not zero-fill allocated memory. Whenever you need to zero-clear allocated memory, use MM_ZERO_CLEAR instead of bzero, to avoid duplication of work in case MM_ALLOC already does it. MM_GC_POINT() invokes a GC when UNDERLYING_MM_SGC_EXP_GC is given, and has no effects otherwise. MM_SETUP(fd) sets GC_dont_gc parameter appropriately when a UNDERLYING_MM_SGC_xxx is given. It also sets GC_free_space_divisor to fd.