Skip to content

Commit 87e59d4

Browse files
memory markdown
1 parent aa190a6 commit 87e59d4

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

MEMORY.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Retro Rocket Memory Model
2+
3+
Retro Rocket handles memory in a way that is both simple for BASIC users and
4+
efficient under the hood. This document explains how memory is divided between
5+
programs, how it grows, and how it is cleaned up when a program ends.
6+
7+
| Area | Description |
8+
|-----------------|-----------------------------------------------------------------------------|
9+
| **Operating System Core** | Kernel, drivers, and system services. This part is always present and not visible to BASIC programs. |
10+
| **BASIC Programs** | Each BASIC program has its **own private heap**, managed by a *buddy allocator*. |
11+
| Program Heap | - Starts empty<br>- Grows in fixed-size regions (typically 1MB)<br>- Allocations (variables, arrays, strings) come only from this private heap<br>- When the program ends, its heap is destroyed in one call, instantly freeing all program memory and removing any fragmentation |
12+
| Memory Reporting | - `MEMPROGRAM` → shows the program’s current live usage<br>- `MEMPEAK` → shows the program’s highest memory use during this run<br>- `MEMUSED` → shows the whole system's memory usage<br>- `MEMFREE` → shows the whole system's memory free amount |
13+
| Other Subsystems | Certain subsystems (like ACPI during boot) also get their own heaps, which are discarded when no longer needed. BASIC users usually don’t see these. |
14+
15+
---
16+
17+
## Why This Matters
18+
19+
- **Isolation**: Each BASIC program has its own memory pool. Programs cannot interfere with each other’s memory.
20+
- **Speed**: Allocation and free are nearly O(1) operations. Programs can create and destroy variables and arrays extremely quickly.
21+
- **Simplicity**: No long cleanup routines are needed. When a program ends, its heap vanishes in one step.
22+
- **Transparency**: You can measure exactly how much memory your program used at its peak, and how much is live right now, using BASIC functions.

0 commit comments

Comments
 (0)