Import boehm-gc snapshot, taken from
[official-gcc.git] / boehm-gc / tests / realloc_test.c
blob1c1668f27d083c4d50ce9cdd92bb8c37642d1887
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "gc.h"
6 #define COUNT 10000000
8 int main(void) {
9 int i;
10 unsigned long last_heap_size = 0;
12 GC_INIT();
14 for (i = 0; i < COUNT; i++) {
15 int **p = GC_MALLOC(sizeof(int *));
16 int *q = GC_MALLOC_ATOMIC(sizeof(int));
18 if (p == 0 || *p != 0) {
19 fprintf(stderr, "GC_malloc returned garbage (or NULL)\n");
20 exit(1);
23 *p = GC_REALLOC(q, 2 * sizeof(int));
25 if (i % 10 == 0) {
26 unsigned long heap_size = (unsigned long)GC_get_heap_size();
27 if (heap_size != last_heap_size) {
28 printf("Heap size: %lu\n", heap_size);
29 last_heap_size = heap_size;
33 return 0;