X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=hs-boehmgc.git;a=blobdiff_plain;f=gc-7.2%2Ftests%2Frealloc_test.c;fp=gc-7.2%2Ftests%2Frealloc_test.c;h=1c1668f27d083c4d50ce9cdd92bb8c37642d1887;hp=0000000000000000000000000000000000000000;hb=324587ba93dc77f37406d41fd2a20d0e0d94fb1d;hpb=2a4ea609491b225a1ceb06da70396e93916f137a diff --git a/gc-7.2/tests/realloc_test.c b/gc-7.2/tests/realloc_test.c new file mode 100644 index 0000000..1c1668f --- /dev/null +++ b/gc-7.2/tests/realloc_test.c @@ -0,0 +1,34 @@ + +#include +#include +#include "gc.h" + +#define COUNT 10000000 + +int main(void) { + int i; + unsigned long last_heap_size = 0; + + GC_INIT(); + + for (i = 0; i < COUNT; i++) { + int **p = GC_MALLOC(sizeof(int *)); + int *q = GC_MALLOC_ATOMIC(sizeof(int)); + + if (p == 0 || *p != 0) { + fprintf(stderr, "GC_malloc returned garbage (or NULL)\n"); + exit(1); + } + + *p = GC_REALLOC(q, 2 * sizeof(int)); + + if (i % 10 == 0) { + unsigned long heap_size = (unsigned long)GC_get_heap_size(); + if (heap_size != last_heap_size) { + printf("Heap size: %lu\n", heap_size); + last_heap_size = heap_size; + } + } + } + return 0; +}