Skip to content

Memory Arenas

MindFry uses arenas — pre-allocated memory pools — for zero-GC performance.

The Psyche Arena stores active lineages in a contiguous memory block.

pub struct PsycheArena {
data: Vec<Lineage>,
generations: Vec<u32>,
free_list: Vec<usize>,
}
OperationComplexityDescription
createO(1)Pop from free list
getO(1)Direct index access
removeO(1)Push to free list

To prevent use-after-free bugs, IDs include a generation:

pub struct LineageId {
index: u32,
generation: u32,
}

The Strata Arena stores historical engrams in ring buffers.

pub struct StrataArena {
rings: Vec<RingBuffer<Engram>>,
depth: usize, // Default: 64
}

Each lineage has a fixed-depth history. When full, oldest entries are overwritten.

The Bond Graph uses Compressed Sparse Row (CSR) format for efficient traversal.

Adjacency Matrix (dense): CSR (sparse):
A B C D values: [0.8, 0.6, 0.5]
A [ 0 .8 0 0 ] col_idx: [1, 2, 3]
B [ 0 0 .6 0 ] row_ptr: [0, 1, 2, 3]
C [ 0 0 0 .5 ]
D [ 0 0 0 0 ]

See Dynamics for how decay and propagation work.