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 requires a surgical operation to get a joke well into a Scotch understanding. The only idea of wit, or rather that inferior variety of the electric talent which prevails occasionally in the North, and which, under the name of “Wut,” is so infinitely distressing to people of good taste, is laughing immoderately at stated intervals.
    Sydney Smith (1771–1845)

    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)