Struct MemoryPool
pub struct MemoryPool {
name: String,
buffer_size: usize,
max_buffers: usize,
free_list: Mutex<RawMutex, Vec<Vec<u8>>>,
total_allocations: AtomicUsize,
cache_hits: AtomicUsize,
pool_size: AtomicUsize,
}Expand description
Memory pool for efficient allocation/deallocation.
Memory pools amortize allocation costs by maintaining a free list of pre-allocated buffers.
Fields§
§name: String§buffer_size: usize§max_buffers: usize§free_list: Mutex<RawMutex, Vec<Vec<u8>>>§total_allocations: AtomicUsize§cache_hits: AtomicUsize§pool_size: AtomicUsizeImplementations§
§impl MemoryPool
impl MemoryPool
pub fn new(
name: impl Into<String>,
buffer_size: usize,
max_buffers: usize,
) -> MemoryPool
pub fn new( name: impl Into<String>, buffer_size: usize, max_buffers: usize, ) -> MemoryPool
Create a new memory pool.
pub fn allocate(&self) -> PooledBuffer<'_>
pub fn allocate(&self) -> PooledBuffer<'_>
Allocate a buffer from the pool.
pub fn buffer_size(&self) -> usize
pub fn buffer_size(&self) -> usize
Get buffer size.
pub fn current_size(&self) -> usize
pub fn current_size(&self) -> usize
Get current pool size.
pub fn preallocate(&self, count: usize)
pub fn preallocate(&self, count: usize)
Pre-allocate buffers.
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§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.