Expand description
GPU-style memory pool with defragmentation and async allocation.
This module provides a pure-Rust simulation of GPU memory management patterns, implementing concepts commonly found in graphics and compute APIs:
- Arena allocator with size-class free lists (see
arena) - Defragmentation — both full compaction and incremental (see
defragmenter) - Buddy allocator for large power-of-2 allocations (see
defragmenter::BuddyAllocator) - Async allocation queue with priority scheduling and pressure callbacks (see
async_pool)
§Quick Start
use scirs2_core::memory_pool::{
arena::ArenaAllocator,
types::{PoolConfig, AsyncAllocRequest},
async_pool::AsyncPool,
};
// Arena allocator
let mut arena = ArenaAllocator::new(PoolConfig::default());
let id = arena.alloc(1024, 256).expect("alloc failed");
let stats = arena.stats();
println!("used: {} / total: {}", stats.used, stats.total);
arena.free(id).expect("free failed");
// Async pool with priority queue
let mut pool = AsyncPool::new(PoolConfig::default());
let req = AsyncAllocRequest::new(4096, /* priority */ 10);
let handle = pool.enqueue(req).expect("enqueue failed");
let completed = pool.process_queue(1);
if let Some(alloc_id) = pool.get_result(handle) {
pool.free(alloc_id).expect("free failed");
}Re-exports§
pub use arena::ArenaAllocator;pub use async_pool::AsyncPool;pub use defragmenter::compact;pub use defragmenter::fragmentation_score;pub use defragmenter::incremental_defrag;pub use defragmenter::BuddyAllocator;pub use types::AllocError;pub use types::AllocationId;pub use types::AllocationStats;pub use types::AsyncAllocRequest;pub use types::BlockState;pub use types::MemoryBlock;pub use types::PoolConfig;pub use types::RequestHandle;
Modules§
- arena
- High-performance arena allocator with size-class free lists.
- async_
pool - Async-style allocation queue with priority scheduling and memory pressure callbacks.
- defragmenter
- Memory defragmentation for the arena allocator.
- types
- Core types for the GPU-style memory pool.