Boehm Garbage Collector - Operation

Operation

The garbage collector works with most unmodified C programs, simply by replacing malloc with GC_MALLOC calls, replacing realloc with GC_REALLOC calls, and removing free calls. The code piece below shows how one can use Boehm instead of traditional malloc and free in C.

#include #include #include int main(void) { int i; GC_INIT; for (i = 0; i < 10000000; ++i) { int **p = (int**)GC_MALLOC(sizeof(int *)); int *q = (int*)GC_MALLOC_ATOMIC(sizeof(int)); assert(*p == 0); *p = (int*)GC_REALLOC(q, 2 * sizeof(int)); if (i % 100000 == 0) printf("Heap size = %zu\n", GC_get_heap_size); } return 0; }

Read more about this topic:  Boehm Garbage Collector

Famous quotes containing the word operation:

    An absolute can only be given in an intuition, while all the rest has to do with analysis. We call intuition here the sympathy by which one is transported into the interior of an object in order to coincide with what there is unique and consequently inexpressible in it. Analysis, on the contrary, is the operation which reduces the object to elements already known.
    Henri Bergson (1859–1941)

    It is critical vision alone which can mitigate the unimpeded operation of the automatic.
    Marshall McLuhan (1911–1980)

    You may read any quantity of books, and you may almost as ignorant as you were at starting, if you don’t have, at the back of your minds, the change for words in definite images which can only be acquired through the operation of your observing faculties on the phenomena of nature.
    Thomas Henry Huxley (1825–95)