Debian Codegraph @

external/bdwgc/tests/realloc_test.c

raw
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "gc.h"
5
6 #define COUNT 10000000
7
8 int main(void) {
9 int i;
10 unsigned long last_heap_size = 0;
11
12 GC_INIT();
13
14 for (i = 0; i < COUNT; i++) {
15 int **p = GC_NEW(int *);
16 int *q = (int*)GC_MALLOC_ATOMIC(sizeof(int));
17
18 if (p == 0 || *p != 0) {
19 fprintf(stderr, "GC_malloc returned garbage (or NULL)\n");
20 exit(1);
21 }
22
23 *p = (int*)GC_REALLOC(q, 2 * sizeof(int));
24
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;
30 }
31 }
32 }
33 return 0;
34 }