Boehm garbage collector
From Encoresoup - The Ultimate Guide to Free/Open Source Software
|
Boehm GC is free software distributed under a permissive free software licence similar to that of X11.
[edit] Example
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. [1]
#include <assert.h>
#include <stdio.h>
#include <gc.h>
int main(void)
{
int i;
GC_INIT();
for (i = 0; i < 10000000; ++i)
{
int **p = GC_MALLOC(sizeof(int *));
int *q = GC_MALLOC_ATOMIC(sizeof(int));
assert(*p == 0);
*p = GC_REALLOC(q, 2 * sizeof(int));
if (i % 100000 == 0)
printf("Heap size = %d\n", GC_get_heap_size());
}
return 0;
}
[edit] References
[edit] External links

![Credit Card Size Digital Video Player [ThinkGeek] Credit Card Size Digital Video Player [ThinkGeek]](http://www.ftjcfx.com/image-3067719-10356334?imgurl=http%3A//www.thinkgeek.com/images/products/front/mini_pmp.jpg)
![USB Memory Watch [ThinkGeek] USB Memory Watch [ThinkGeek]](http://www.ftjcfx.com/image-3067719-10356334?imgurl=http%3A//www.thinkgeek.com/images/products/front/usb_memory_watch.jpg)
![Micro Spy Remote [ThinkGeek] Micro Spy Remote [ThinkGeek]](http://www.ftjcfx.com/image-3067719-10356334?imgurl=http%3A//www.thinkgeek.com/images/products/front/ninja_remote_new.jpg)

