memkit 0.2.0-beta.1

Deterministic, intent-driven memory allocation for systems requiring predictable performance
Documentation
//! Allocator configuration.

/// Configuration for the memory allocator.
#[derive(Debug, Clone)]
pub struct MkConfig {
    /// Size of the frame arena per thread (default: 16 MB)
    pub frame_arena_size: usize,

    /// Size classes for the slab allocator
    pub slab_size_classes: Vec<usize>,

    /// Number of pages to pre-allocate per size class
    pub slab_pages_per_class: usize,

    /// Page size for slab allocator (default: 64 KB)
    pub slab_page_size: usize,

    /// Enable memory budgeting
    pub enable_budgets: bool,

    /// Global memory limit (0 = unlimited)
    pub global_memory_limit: usize,

    /// Enable debug features (memory poisoning, etc.)
    pub debug_mode: bool,
}

impl Default for MkConfig {
    fn default() -> Self {
        Self {
            frame_arena_size: 16 * 1024 * 1024, // 16 MB
            slab_size_classes: vec![16, 32, 64, 128, 256, 512, 1024, 2048, 4096],
            slab_pages_per_class: 4,
            slab_page_size: 64 * 1024, // 64 KB
            enable_budgets: false,
            global_memory_limit: 0,
            debug_mode: cfg!(debug_assertions),
        }
    }
}

impl MkConfig {
    /// Create a minimal config for testing or constrained environments.
    pub fn minimal() -> Self {
        Self {
            frame_arena_size: 1024 * 1024, // 1 MB
            slab_size_classes: vec![32, 128, 512, 2048],
            slab_pages_per_class: 1,
            slab_page_size: 16 * 1024, // 16 KB
            enable_budgets: false,
            global_memory_limit: 0,
            debug_mode: false,
        }
    }

    /// Create a config optimized for high-throughput scenarios.
    pub fn high_throughput() -> Self {
        Self {
            frame_arena_size: 64 * 1024 * 1024, // 64 MB
            slab_size_classes: vec![16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192],
            slab_pages_per_class: 8,
            slab_page_size: 128 * 1024, // 128 KB
            enable_budgets: false,
            global_memory_limit: 0,
            debug_mode: false,
        }
    }
}