pub struct StratifiedMemoryPool { /* private fields */ }Expand description
Multi-size memory pool with automatic bucket selection.
Instead of having a single buffer size, this pool maintains separate pools for different size classes. Allocations are rounded up to the smallest bucket that fits.
§Example
use ringkernel_core::memory::{StratifiedMemoryPool, SizeBucket};
let pool = StratifiedMemoryPool::new("my_pool");
// Allocate various sizes - each goes to appropriate bucket
let tiny_buf = pool.allocate(100); // Uses Tiny bucket (256B)
let medium_buf = pool.allocate(2000); // Uses Medium bucket (4KB)
// Check statistics
let stats = pool.stats();
println!("Hit rate: {:.1}%", stats.hit_rate() * 100.0);Implementations§
Source§impl StratifiedMemoryPool
impl StratifiedMemoryPool
Sourcepub fn new(name: impl Into<String>) -> StratifiedMemoryPool
pub fn new(name: impl Into<String>) -> StratifiedMemoryPool
Create a new stratified pool with default settings.
Creates pools for all bucket sizes with 16 buffers per bucket.
Sourcepub fn with_capacity(
name: impl Into<String>,
max_buffers_per_bucket: usize,
) -> StratifiedMemoryPool
pub fn with_capacity( name: impl Into<String>, max_buffers_per_bucket: usize, ) -> StratifiedMemoryPool
Create a pool with specified max buffers per bucket.
Sourcepub fn allocate(&self, size: usize) -> StratifiedBuffer<'_>
pub fn allocate(&self, size: usize) -> StratifiedBuffer<'_>
Allocate a buffer of at least the requested size.
The buffer may be larger than requested (rounded up to bucket size).
Sourcepub fn allocate_bucket(&self, bucket: SizeBucket) -> StratifiedBuffer<'_>
pub fn allocate_bucket(&self, bucket: SizeBucket) -> StratifiedBuffer<'_>
Allocate from a specific bucket.
Sourcepub fn max_buffers_per_bucket(&self) -> usize
pub fn max_buffers_per_bucket(&self) -> usize
Get max buffers per bucket.
Sourcepub fn bucket_size(&self, bucket: SizeBucket) -> usize
pub fn bucket_size(&self, bucket: SizeBucket) -> usize
Get current size of a specific bucket pool.
Sourcepub fn total_pooled(&self) -> usize
pub fn total_pooled(&self) -> usize
Get total buffers currently pooled across all buckets.
Sourcepub fn stats(&self) -> StratifiedPoolStats
pub fn stats(&self) -> StratifiedPoolStats
Get statistics snapshot.
Sourcepub fn preallocate(&self, bucket: SizeBucket, count: usize)
pub fn preallocate(&self, bucket: SizeBucket, count: usize)
Pre-allocate buffers for a specific bucket.
Sourcepub fn preallocate_all(&self, count_per_bucket: usize)
pub fn preallocate_all(&self, count_per_bucket: usize)
Pre-allocate buffers for all buckets.
Auto Trait Implementations§
impl !Freeze for StratifiedMemoryPool
impl !RefUnwindSafe for StratifiedMemoryPool
impl Send for StratifiedMemoryPool
impl Sync for StratifiedMemoryPool
impl Unpin for StratifiedMemoryPool
impl UnwindSafe for StratifiedMemoryPool
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
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>
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>
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