Core Concepts / Arena Memory Management

Arena Memory Management

Aero has two coexisting memory models: ownership + borrowing (see References & Borrowing) and the Arena region allocation designed for hot loops.

Why Arena Is Needed

Zero-allocation hot loops: frequent allocation/freeing causes GC/allocator overhead. An Arena allocates a pool once, the program takes slots in order, and the whole pool is reset after use — no per-object allocation.

Basic Usage

let a = arena(128);     // 创建 128 槽的池(每槽 8 字节)
a.alloc(16);            // 顺序取 16 个槽
a.reset();              // 复用整池

Key Rules

Auto-reset at the end of a brace blockslots alloc'd inside the block are reclaimed and reused automatically
Abort when the pool is fullbetter to be safe than to silently corrupt memory
Cannot be copied / moved / reassignedenforced at compile time
Heap objects that outlive functionsuse malloc-style strings (int_to_str + str_free)
fn process() {
    let mem = arena(1024);
    // 循环里反复取槽,不分配
    {
        mem.alloc(64);
    }   // 块结束自动重置
    mem.alloc(32);
}

Arena suits scenarios with a clear lifetime and heavy reuse — "per frame / per row / per request" — and is an important tool for writing performance kernels in Aero.

Aero 文档 · 基于 Aero 1.2.0 文档整理 · MIT
SereinTeam