# memkit
**Core CPU memory allocation primitives for the memkit ecosystem.**
> **Version:** 0.1.0-alpha.1
[](https://crates.io/crates/memkit)
[](https://docs.rs/memkit)
[](https://opensource.org/licenses/MPL-2.0)
## Overview
memkit provides deterministic, intent-driven memory allocation for game engines and real-time applications. It offers predictable performance through explicit lifetimes and zero-cost abstractions.
## Features
- **Frame Arenas** — O(1) bump allocation, instant bulk reset per frame
- **Object Pools** — O(1) allocation/deallocation for small objects
- **Heap Allocation** — Tracked heap allocations with statistics
- **Scoped Allocation** — RAII-style checkpoint/restore within frames
- **Thread-Local Fast Paths** — Per-thread arenas avoid contention
## Quick Start
```rust
use memkit::{MkAllocator, MkConfig};
let alloc = MkAllocator::new(MkConfig::default());
// Game loop
loop {
alloc.begin_frame();
// Frame allocations - ultra fast, reset automatically
let positions = alloc.frame_slice::<[f32; 3]>(1000).unwrap();
let velocities = alloc.frame_slice::<[f32; 3]>(1000).unwrap();
// Pool allocations - returned to pool on drop
let entity = alloc.pool_box(Entity::new()).unwrap();
// Scoped allocations
{
let _scope = alloc.scope();
let temp = alloc.frame_box(TempData::new()).unwrap();
// temp freed when scope drops
}
alloc.end_frame(); // Instant reset
}
```
## Types
| `MkAllocator` | Main allocator entry point |
| `MkConfig` | Allocator configuration |
| `MkFrameBox<T>` | Frame-allocated box |
| `MkFrameSlice<T>` | Frame-allocated slice |
| `MkFrameVec<T>` | Frame-allocated vector |
| `MkPoolBox<T>` | Pool-allocated box |
| `MkHeapBox<T>` | Heap-allocated box |
| `MkScope` | Scoped checkpoint guard |
## Configuration
```rust
let config = MkConfig {
frame_arena_size: 64 * 1024 * 1024, // 64 MB per thread
slab_size_classes: vec![16, 32, 64, 128, 256, 512, 1024, 2048, 4096],
debug_mode: cfg!(debug_assertions),
..Default::default()
};
```
## License
This project is licensed under the Mozilla Public License 2.0 - see the [LICENSE.md](../LICENSE.md) file for details.