realloc_test.c 680 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "gc.h"
  4. #define COUNT 10000000
  5. int main(void) {
  6. int i;
  7. unsigned long last_heap_size = 0;
  8. GC_INIT();
  9. for (i = 0; i < COUNT; i++) {
  10. int **p = GC_NEW(int *);
  11. int *q = (int*)GC_MALLOC_ATOMIC(sizeof(int));
  12. if (p == 0 || *p != 0) {
  13. fprintf(stderr, "GC_malloc returned garbage (or NULL)\n");
  14. exit(1);
  15. }
  16. *p = (int*)GC_REALLOC(q, 2 * sizeof(int));
  17. if (i % 10 == 0) {
  18. unsigned long heap_size = (unsigned long)GC_get_heap_size();
  19. if (heap_size != last_heap_size) {
  20. printf("Heap size: %lu\n", heap_size);
  21. last_heap_size = heap_size;
  22. }
  23. }
  24. }
  25. return 0;
  26. }