#include #include #include #include #include #include #include #include "gc.h" void out_of_memory(void) { fprintf(stderr, "Out of memory!\n"); abort(); } int main(int argc, char **argv) { gc_root_t list_root; int count = 0; gc_init(1024, 256*1024*1024); srand((unsigned int)time(NULL)); register_gc_root(&list_root, NIL); while (1) { int r = rand() & 0xffff; if (r == 0) list_root.value = make_fixnum(rand()); else { switch (r & 7) { case 0: list_root.value = cons(make_fixnum(rand()), list_root.value); break; case 1: list_root.value = cons(list_root.value, make_byte_string(256, '\0')); break; case 2: list_root.value = make_box(list_root.value); break; case 3: list_root.value = cons(list_root.value, cons(make_fixnum(-1), NIL)); get_pair(get_pair(list_root.value)->cdr)->cdr = list_root.value; ++count; break; case 4: case 5: case 6: case 7: { value_t vec = make_vector(4, NIL); _get_vector(vec)->elements[r & 3] = list_root.value; list_root.value = vec; } break; } } ++count; if (count >= 10000000) { fprintf(stderr, "%0.3f usec / GC; max. limit was %u bytes; %0.3f seconds spent in %d GCs.\n", (1000000 * (gc_stats.total_ticks / (double)CLOCKS_PER_SEC)) / gc_stats.collections, gc_stats.high_water, gc_stats.total_ticks / (double)CLOCKS_PER_SEC, gc_stats.collections); gc_stats.collections = 0; gc_stats.total_ticks = 0; gc_stats.high_water = 0; count = 0; break; } } unregister_gc_root(&list_root); return 0; } /* vim:set sw=2 expandtab: */