Expand description
§ruapc-bufpool
A high-performance memory pool using buddy memory allocation algorithm for efficient fixed-size buffer management. This crate is part of the ruapc project.
§Features
- Buddy Memory Allocation: Supports allocation of 1MiB, 4MiB, 16MiB, and 64MiB buffers
- Both Sync and Async APIs: Designed for tokio environments with async-first design
- Automatic Memory Reclamation: Buffers are automatically returned to the pool on drop
- Memory Limits: Configurable maximum memory usage with async waiting when limits are reached
- Custom Allocators: Pluggable allocator trait for memory allocation backend
- O(1) Buddy Merging: Intrusive doubly-linked list with O(1) free/merge operations
§Example
use ruapc_bufpool::{BufferPool, BufferPoolBuilder};
// Create a buffer pool with 256MiB max memory
let pool = BufferPoolBuilder::new()
.max_memory(256 * 1024 * 1024)
.build();
// Allocate a 1MiB buffer synchronously
let buffer = pool.allocate(1024 * 1024)?;
assert!(buffer.len() >= 1024 * 1024);
// Buffer is automatically returned to the pool when dropped
drop(buffer);§Async Example
use ruapc_bufpool::{BufferPool, BufferPoolBuilder};
let pool = BufferPoolBuilder::new()
.max_memory(256 * 1024 * 1024)
.build();
// Allocate asynchronously - will wait if memory limit is reached
let buffer = pool.async_allocate(4 * 1024 * 1024).await?;Structs§
- Buffer
- A buffer allocated from the pool.
- Buffer
Pool - A high-performance memory pool using buddy memory allocation.
- Buffer
Pool Builder - Builder for creating a
BufferPoolwith custom configuration. - Default
Allocator - Default allocator using the standard library’s global allocator.
Traits§
- Allocator
- Trait for memory allocation backends.