1;;;; test-gc-hooks.scm
2
3(import (chicken gc))
4
5#>
6
7static int count = 0;
8
9static void
10gc_start(int mode)
11{
12  printf(">>>>> GC pre hook - mode=%d, count=%d\n", mode, count++);
13}
14
15static void
16gc_end(int mode, long ms)
17{
18  printf("<<<<< GC post hook - mode=%d, count=%d, ms=%ld\n", mode, --count, ms);
19}
20
21<#
22
23(set-gc-report! #t)
24
25(foreign-code #<<EOF
26C_pre_gc_hook = gc_start;
27C_post_gc_hook = gc_end;
28EOF
29)
30
31(print "major gc ...")
32(gc)
33(print "minor gc ...")
34(gc #f)
35(print "alloc ...")
36(make-string 10000000)
37(print "resize ...")
38(##sys#gc '())
39(print "major gc ...")
40(gc)
41(print "minor gc ...")
42(gc #f)
43
44(assert (zero? (foreign-value "count" int)))
45