少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
#include <stdio.h>
#include <stdlib.h>
#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_NEW(int *);
    int *q = (int*)GC_MALLOC_ATOMIC(sizeof(int));
 
    if (p == 0 || *p != 0) {
      fprintf(stderr, "GC_malloc returned garbage (or NULL)\n");
      exit(1);
    }
 
    *p = (int*)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;
}