Expand description
Arena allocator for inference pipeline tensor memory management.
Inference pipelines allocate many small tensors. An arena allocator avoids
per-tensor heap allocation by bump-allocating from pre-allocated slabs.
This module provides TensorArena, ArenaRegion, ArenaSlice,
ArenaStats, and ArenaError.
§Design
The arena is organized as a list of fixed-size ArenaRegion slabs.
Each region is a Vec<u8> with a bump pointer (offset). Allocations
are always 8-byte aligned. When a region is full a new one is created.
Lifetimes are avoided by representing allocated memory as (start, end)
byte ranges within a region’s slab, wrapped in ArenaSlice.
§Example
use ipfrs_tensorlogic::tensor_arena::{TensorArena, ArenaError};
let mut arena = TensorArena::new(1024 * 1024); // 1 MB regions
// Allocate space for 4 f32 values (16 bytes)
let slice = arena.allocate(4 * 4);
// Write and read back
slice.write_f32(&mut arena, &[1.0, 2.0, 3.0, 4.0]).expect("example: should succeed in docs");
let values = slice.read_f32(&arena);
assert_eq!(values, &[1.0f32, 2.0, 3.0, 4.0]);
// Reset for reuse (no deallocation)
arena.reset_all();Structs§
- Arena
Region - A contiguous slab of memory with a bump pointer.
- Arena
Slice - A handle to a contiguous byte range inside a
TensorArenaregion. - Arena
Stats - Cumulative statistics for a
TensorArena. - Tensor
Arena - Bump-allocating arena for inference-pipeline tensors.
Enums§
- Arena
Error - Errors that can occur during arena operations.