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:

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

    “Waiting for the race to become official, he began to feel as if he had as much effect on the final outcome of the operation as a single piece of a jumbo jigsaw puzzle has to its predetermined final design. Only the addition of the missing fragments of the puzzle would reveal if the picture was as he guessed it would be.”
    —Stanley Kubrick (b. 1928)

    “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)