Go to the first, previous, next, last section, table of contents.


Typed memory allocation

There are many cases when the allocated memory may contain both data and pointers. In this case the memory can be allocated using the normal GC_malloc() function and let the collector assume that all the contained data are pointers. This is both inefficient and error-prone because it is possible, even with a small probability, that integers have the same value as an existing pointer, thus keeping a reference to a memory zone and preventing it to be deallocated.

Fortunately there's a better approach for this. At the time of the allocation, it is possible to inform the collector where the pointers are located inside it. This mechanism is called typed memory.

To describe a memory zone a descriptor of it has to be constructed first. The GC_make_descriptor() function is used for this; it takes as arguments a bitmap describing the memory zone and the number of meaningful bits in the bitmap. The less signifiant bit in the bitmap corresponds to the first word in the memory zone.

The descriptor returned by the GC_make_descriptor() function is then passed to the GC_malloc_explicitly_typed() or GC_calloc_explicitly_typed()functions to allocate a memory zone. One caveat though, the memory returned by these functions cannot be reallocated at a later point in time.

The typed memory functions have their prototypes in the `gc_typed.h' file.


Go to the first, previous, next, last section, table of contents.