Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created December 14, 2010 07:04
Show Gist options
  • Save rjungemann/740094 to your computer and use it in GitHub Desktop.
Save rjungemann/740094 to your computer and use it in GitHub Desktop.
Boehm GC Example
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment