memkit-async
Async-aware memory allocators for the memkit ecosystem.
Version: 0.1.0-alpha.1
Overview
memkit-async provides async-native memory allocators designed for concurrent workloads. These allocators understand async context and behave correctly across .await points.
Features
- Task-Local Allocators — Each async task gets isolated allocation context
- Backpressure Support — Configurable behavior when memory is exhausted
- Zero-Copy Channels — Transfer ownership between tasks without copying
- Async Pools — Object pools with async acquire semantics
- Safe Across
.await— Allocations tracked per-task, not per-thread
The Problem
// UNSAFE: Frame data may be invalid after await
let data = alloc.frame_box;
some_async_op.await; // Task may resume on different thread!
use_data; // Undefined behavior
The Solution
use ;
// SAFE: Async-aware allocator tracks task state
let alloc = new;
let frame = alloc.begin_frame.await;
let data = alloc..await;
some_async_op.await; // Allocator ensures validity
use_data; // Safe!
drop;
Quick Start
use ;
// Async pool with backpressure
let pool = new;
pool.add.unwrap;
let buffer = pool.acquire.await.unwrap;
// buffer returned to pool on drop
// Zero-copy channel
let channel = bounded;
let = channel.split;
tx.send.await.unwrap;
let received = rx.recv.await.unwrap;
Backpressure Policies
| Policy | Behavior |
|---|---|
Wait |
Yield and retry until memory available |
Fail |
Return error immediately |
Timeout(Duration) |
Wait up to timeout, then fail |
Evict |
Evict LRU items to make room |
Types
| Type | Description |
|---|---|
MkAsyncFrameAlloc |
Async-aware frame allocator |
MkAsyncFrameGuard |
Frame scope guard |
MkAsyncPool<T> |
Async object pool |
MkPoolGuard<T> |
Pool item guard |
MkAsyncChannel<T> |
Zero-copy async channel |
MkAsyncBox<T> |
Async-safe box |
MkAsyncVec<T> |
Async-safe vector |
MkAsyncBarrier |
Async synchronization barrier |
MkAsyncSemaphore |
Async semaphore |
Tokio Integration
Enable the tokio feature for Tokio-specific functionality:
[]
= { = "0.1.0-alpha.1", = ["tokio"] }
Task-Local Allocator Context
use ;
use ;
async
Runtime Functions
| Function | Description |
|---|---|
with_allocator(alloc, future) |
Run future with task-local allocator |
current_allocator() |
Get current task's allocator (panics if none) |
try_current_allocator() |
Get current allocator (returns Option) |
mk_spawn(future) |
Spawn task with inherited allocator |
with_timeout(duration, future) |
Run with Tokio timeout |
yield_now() |
Yield to Tokio runtime |
sleep(duration) |
Tokio sleep |
License
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE.md file for details.