aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/growheap.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/growheap.zc
a
Diffstat (limited to 'tests/programs/growheap.zc')
-rw-r--r--tests/programs/growheap.zc32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/programs/growheap.zc b/tests/programs/growheap.zc
new file mode 100644
index 0000000..07e10a6
--- /dev/null
+++ b/tests/programs/growheap.zc
@@ -0,0 +1,32 @@
+// the heap grows past its initial size: eight live blocks of 300000 words
+// don't fit in the 393216-word start, so the allocator takes more memory from
+// the host, and a block bigger than the start fits once they are freed
+let keep[8];
+unchecked fn fill(n) {
+ let i = 0, a;
+ while (i < n) { a = new(300000); a[0] = i + 1; a[299999] = (i + 1) * 3; keep[i] = a; i++; }
+ return 0;
+}
+unchecked fn total(n) {
+ let i = 0, a, sum = 0;
+ while (i < n) { a = keep[i]; sum = sum + a[0] + a[299999]; i++; }
+ return sum;
+}
+unchecked fn drop(n) {
+ let i = 0;
+ while (i < n) { free(keep[i]); keep[i] = 0; i++; }
+ return 0;
+}
+fn main() {
+ let a, start = heap_size();
+ fill(8);
+ put_n(total(8)); put_c(' ');
+ put_n(heap_size() > start); put_c(' ');
+ drop(8);
+ scrub(); gc();
+ a = new(3000000);
+ a[2999999] = 7;
+ put_n(a[2999999]); put_c(' ');
+ put_n(heap_size() >= 3000000); put_c(10);
+ return 0;
+}