pub struct MemoryPool { /* private fields */ }Expand description
Memory pool for efficient allocation and reuse of buffers.
Maintains separate pools for different size classes to minimize fragmentation. Thread-safe via internal locking.
§Performance
- Cache hit: O(1) - reuse existing buffer
- Cache miss: O(1) - allocate new buffer
- Return: O(1) - add to pool
§Example
use ronn_core::memory_pool::MemoryPool;
let pool = MemoryPool::new();
// Get buffer (cache miss - allocates)
let mut buf = pool.get(1024);
// Use buffer...
// Return buffer (adds to pool)
pool.return_buffer(buf);
// Get buffer again (cache hit - reuses)
let buf2 = pool.get(1024);Implementations§
Source§impl MemoryPool
impl MemoryPool
Sourcepub fn with_config(config: PoolConfig) -> Self
pub fn with_config(config: PoolConfig) -> Self
Create a new memory pool with custom configuration.
Sourcepub fn get(&self, size: usize) -> PooledBuffer
pub fn get(&self, size: usize) -> PooledBuffer
Sourcepub fn return_buffer(&self, buffer: PooledBuffer)
pub fn return_buffer(&self, buffer: PooledBuffer)
Return a buffer to the pool for reuse.
If the pool for this size class is full, the buffer is dropped.
§Arguments
buffer- The buffer to return
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MemoryPool
impl RefUnwindSafe for MemoryPool
impl Send for MemoryPool
impl Sync for MemoryPool
impl Unpin for MemoryPool
impl UnwindSafe for MemoryPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more