-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgc-demo-programs.lisp
More file actions
54 lines (49 loc) · 1.45 KB
/
Copy pathgc-demo-programs.lisp
File metadata and controls
54 lines (49 loc) · 1.45 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
; === GC Visualization Demos ===
; Demo 1: Simple allocation wave
; Repeatedly allocate lists and trigger collections to visualize
; allocation/collection waves in the heap view.
(define (make-garbage n)
(if (= n 0)
nil
(cons n (make-garbage (- n 1)))))
(define (demo-wave)
(begin
(print '(=== Wave Demo ===))
(make-garbage 100)
(gc)
(make-garbage 100)
(gc)
(make-garbage 100)))
; Demo 2: Fragmentation test
; Builds many lists of varying length to fragment mark-sweep heaps
; so you can observe free-list gaps and copying compaction behavior.
(define (demo-fragment)
(begin
(print '(=== Fragmentation Demo ===))
(map (lambda (n) (range 1 n))
(range 1 20))))
; Demo 3: Generational test
; Keeps some survivors while allocating short-lived objects so the
; generational backend shows nursery promotions and survivor retention.
(define (demo-generational)
(begin
(print '(=== Generational Demo ===))
(define survivors (list 1 2 3))
(define (loop n)
(if (= n 0)
survivors
(begin
(cons n nil)
(loop (- n 1)))))
(loop 100)))
; Demo 4: Tree allocation
; Constructs a full binary tree to stress recursive allocation and
; highlight how each backend handles large graph structures.
(define (demo-tree)
(begin
(print '(=== Tree Demo ===))
(define (tree d)
(if (= d 0)
'leaf
(list (tree (- d 1)) (tree (- d 1)))))
(tree 6)))