aegis-memory

Crates.ioaegis-memory
lib.rsaegis-memory
version0.1.7
created_at2026-01-20 02:31:34.295357+00
updated_at2026-01-24 03:49:15.835549+00
descriptionMemory management for Aegis database
homepagehttps://automatanexus.com
repositoryhttps://github.com/AutomataNexus/Aegis-DB
max_upload_size
id2055679
size38,631
Andrew Jewell Sr. (AutomataControls)

documentation

README

AegisDB Logo

aegis-memory

License Rust Version AegisDB

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

[dependencies]
aegis-memory = { path = "../aegis-memory" }

Arena Allocator

The arena allocator is ideal for request-scoped allocations where all memory can be freed at once:

use aegis_memory::arena::Arena;

// Create an arena with 1MB initial capacity
let arena = Arena::new(1024 * 1024);

// Allocate memory (very fast - just bumps a pointer)
let buffer = arena.alloc(1024);

// Use the buffer...
buffer[0] = 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:

cargo bench -p aegis-memory

Typical results:

  • Arena allocation: ~5ns per allocation
  • Standard allocation: ~25ns per allocation
  • Arena reset: ~100ns (constant, regardless of allocation count)

Tests

cargo test -p aegis-memory

Test count: 5 tests

License

Apache-2.0

Commit count: 0

cargo fmt