Created
December 14, 2010 07:04
-
-
Save rjungemann/740094 to your computer and use it in GitHub Desktop.
Boehm GC Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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