previous up next     contents index
Next: Library Functions Up: MzScheme Architecture Previous: Library Functions

Memory Allocation

      MzScheme uses both  malloc and the allocation routines of the conservative garbage collector. Embedding/extension C/C++ code may use either allocation method, keeping in mind that pointers to garbage-collectable blocks in malloced memory are invisible (i.e., such pointers will not prevent the block from being garbage-collected).

The collector allocation routines are  scheme_malloc,  scheme_malloc_atomic,  scheme_malloc_stubborn, and  scheme_malloc_uncollectable. The first three return memory that is automatically garbage collected, while the last returns uncollectable memory. All four return memory that can contain (visible) pointers to garbage-collected memory.

Atomic memory is used for strings or other blocks of memory which do not contain pointers. Atomic memory can also be used to store intentionally-hidden pointers.

Stubborn memory is an optimization allowing generational collection. Once the contents of a stubborn block are set, the function  scheme_end_stubborn_change can be called; this function call serves as a promise that the contents of the block will never be changed again (until after it is garbage-collected).

  If a MzScheme extension stores Scheme pointers in a global variable, then that variable must be registered with  scheme_register_extension_global; this makes the pointer visible to the garbage collector.





PLT