aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/buddy.zc
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/programs/buddy.zc
a
Diffstat (limited to 'tests/programs/buddy.zc')
-rw-r--r--tests/programs/buddy.zc16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/programs/buddy.zc b/tests/programs/buddy.zc
new file mode 100644
index 0000000..ab351d2
--- /dev/null
+++ b/tests/programs/buddy.zc
@@ -0,0 +1,16 @@
+// the buddy allocator: 20000 small blocks, freed, merge back into one big one
+let keep[20000];
+fn main() {
+ let i = 0, p;
+ while (i < 20000) { keep[i] = new(2); i++; } // 20000 8-word blocks
+ put_n(largest_free()); put_c(' ');
+ i = 0; while (i < 20000) { free(keep[i]); keep[i] = 0; i++; }
+ scrub(); // stale stack words would keep the quarantined blocks
+ gc();
+ put_n(largest_free()); put_c(' ');
+ p = new(200000); // only possible if the small blocks merged back
+ put_n(osize(p) >= 200000); put_c(' ');
+ free(d*p);
+ put_n(live_objects()); put_c(10);
+ return 0;
+}