aegis-memory
Memory management and allocation for the Aegis Database Platform.
Overview
aegis-memory provides efficient memory management primitives including arena allocators and buffer pools. It's designed for high-performance database operations where memory allocation patterns are predictable.
Features
- Arena Allocators - Fast bump allocation with batch deallocation
- Memory Pools - Pre-allocated fixed-size block pools
- Zero-Copy Operations - Minimize memory copies where possible
- Thread-Safe - Lock-free and lock-based options
Modules
| Module | Description |
|---|---|
arena |
Arena-based memory allocator |
Usage
[]
= { = "../aegis-memory" }
Arena Allocator
The arena allocator is ideal for request-scoped allocations where all memory can be freed at once:
use Arena;
// Create an arena with 1MB initial capacity
let arena = new;
// Allocate memory (very fast - just bumps a pointer)
let buffer = arena.alloc;
// Use the buffer...
buffer = 42;
// Reset frees all allocations at once (O(1))
arena.reset;
Benefits
| Operation | Arena | Standard Allocator |
|---|---|---|
| Allocate | O(1) bump | O(log n) search |
| Deallocate | Deferred | O(log n) coalesce |
| Reset | O(1) | N/A |
Design
Arena Memory Layout:
┌────────────────────────────────────────────┐
│ Block 1 │
│ ┌─────────┬─────────┬─────────┬──────────┐│
│ │ Alloc 1 │ Alloc 2 │ Alloc 3 │ Free ││
│ └─────────┴─────────┴─────────┴──────────┘│
├────────────────────────────────────────────┤
│ Block 2 (allocated when Block 1 full) │
│ ┌─────────┬──────────────────────────────┐│
│ │ Alloc 4 │ Free ││
│ └─────────┴──────────────────────────────┘│
└────────────────────────────────────────────┘
Benchmarks
Run benchmarks:
Typical results:
- Arena allocation: ~5ns per allocation
- Standard allocation: ~25ns per allocation
- Arena reset: ~100ns (constant, regardless of allocation count)
Tests
Test count: 5 tests
License
Apache-2.0