memkit-async 0.1.1-beta.1

Async-aware memory allocators for memkit
Documentation

memkit-async

Task-Local, Async-Native Memory Management for Rust.

Crates.io Documentation License: MPL-2.0


โšก The Async Challenge

In traditional Rust async, using stack-based or frame-based allocators is dangerous. Resuming a task on a different thread or after a lifetime has expired leads to undefined behavior.

memkit-async solves this by introducing Task-Local Allocation Contexts. Your memory remains valid and local to the logical task, even as it migrates across the thread pool of an executor like tokio.

๐Ÿ’Ž The Async Advantage

Feature Standard Box memkit-async
Fragmentation High (Global Heap) Zero (Task Arenas)
Locality Cache-indifferent High (Contiguous)
Safety Runtime-only Compile-time & Task-local
Pipelining Locks on contention Lock-free via Locality

โœจ Features

  • ๐Ÿงถ Task-Local Arenas โ€” Each async task gets its own isolated, high-speed allocation context.
  • ๐Ÿ›‘ Backpressure Semantics โ€” Configurable behavior (Wait, Fail, Timeout) when memory limits are reached.
  • ๐Ÿ“ฆ Lock-Free Object Pools โ€” High-performance object reuse with async acquisition.
  • ๐Ÿš€ Zero-Copy Channels โ€” Move ownership of entire arenas between tasks without a single mem-copy.
  • ๐Ÿ›ก๏ธ Await-Safe โ€” Integrated with the task lifecycle to ensure memory remains valid across .await.

๐Ÿ› ๏ธ Quick Start

use memkit_async::{MkAsyncFrameAlloc, MkAsyncFrameConfig};

#[tokio::main]
async fn main() {
    let alloc = MkAsyncFrameAlloc::new(MkAsyncFrameConfig::default());
    
    // Begin a task-scoped frame
    let frame = alloc.begin_frame().await;
    
    // Allocate high-speed data that is safe across await points
    let data = alloc.alloc::<BigData>().await;
    
    do_some_io().await; // Task might move threads here...
    
    process(data);      // ...but our memory remains safe and contiguous!
    
    drop(frame);
}

๐Ÿ—๏ธ Backpressure Policies

When your async tasks are memory-hungry, memkit-async keeps the system stable:

Policy Behavior
Wait Suspends the task until memory is available.
Fail Immediately returns a CapacityReached error.
Timeout Waits for a duration before failing.
Evict Discards the oldest entries (useful for caches).

๐Ÿ”Œ Integration

Enable the tokio feature for first-class support for the Tokio runtime:

[dependencies]

memkit-async = { version = "0.1.1-beta.1", features = ["tokio"] }

โš–๏ธ License

Licensed under the Mozilla Public License 2.0. See LICENSE.md for details.