pub struct Chunk { /* private fields */ }Expand description
A wholesale block of memory obtained via direct_alloc out of which the MemoryPool carves
the *mut u8 slots handed to consumers.
A Chunk serves allocations in two ways.
- Reusing a deallocated section tracked in its FreeList (after defragmenting it).
- Bumping the internal cursor over the untouched tail of the block.
The backing block is released via direct_dealloc when the Chunk is dropped.
Implementations§
Source§impl Chunk
impl Chunk
Sourcepub fn new(capacity: usize) -> Option<Chunk>
pub fn new(capacity: usize) -> Option<Chunk>
Allocates a new Chunk of capacity bytes using direct_alloc.
Returns None if the system refuses to hand us the memory.
pub fn capacity(&self) -> usize
Sourcepub fn contains(&self, ptr: *const u8) -> bool
pub fn contains(&self, ptr: *const u8) -> bool
Checks if ptr points into the memory block owned by this Chunk.
Sourcepub fn can_allocate(&self, size: usize, align: usize) -> bool
pub fn can_allocate(&self, size: usize, align: usize) -> bool
Checks if this Chunk has a slot of size bytes aligned to align available, either in
its FreeList or in its untouched tail. Call Self::defragment first for best results.
Sourcepub fn defragment(&mut self)
pub fn defragment(&mut self)
Sourcepub fn allocate(&mut self, size: usize, align: usize) -> Option<*mut u8>
pub fn allocate(&mut self, size: usize, align: usize) -> Option<*mut u8>
Obtains a *mut u8 slot of size bytes aligned to align from this Chunk.
§Order of Operations
- Defragment the FreeList via Self::defragment.
- Try to recycle a deallocated section via Self::reclaim.
- Fall back to bumping the cursor over the untouched tail via Self::bump.
Trait Implementations§
Auto Trait Implementations§
impl !Send for Chunk
impl !Sync for Chunk
impl Freeze for Chunk
impl RefUnwindSafe for Chunk
impl Unpin for Chunk
impl UnsafeUnpin for Chunk
impl UnwindSafe for Chunk
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