Struct contiguous_mem::AllocationTracker
source · pub struct AllocationTracker { /* private fields */ }Expand description
A structure that keeps track of unused regions of memory within provided bounds.
Implementations§
source§impl AllocationTracker
impl AllocationTracker
sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Constructs a new AllocationTracker of the provided size.
Arguments
size- The total size of the memory region that will be tracked.
sourcepub fn whole_range(&self) -> ByteRange
pub fn whole_range(&self) -> ByteRange
Returns a ByteRange encompassing the entire tracked memory region.
sourcepub fn resize(&mut self, new_size: usize) -> Result<(), ContiguousMemoryError>
pub fn resize(&mut self, new_size: usize) -> Result<(), ContiguousMemoryError>
Tries resizing the available memory range represented by this structure
to provided new_size, or an ContiguousMemoryError::Unshrinkable
error if the represented memory range cannot be shrunk enough to fit
the desired size.
sourcepub fn shrink_to_fit(&mut self) -> Option<usize>
pub fn shrink_to_fit(&mut self) -> Option<usize>
Removes tailing area of tracked memory bounds if it is marked as free and returns the new (reduced) size.
If the tailing area was marked as occupied None is returned instead.
sourcepub fn peek_next(&self, layout: Layout) -> Option<ByteRange>
pub fn peek_next(&self, layout: Layout) -> Option<ByteRange>
Returns the next free memory region that can accommodate the given type
layout.
If the layout cannot be safely stored within any free segments of the
represented memory region, None is returned instead.
sourcepub fn take(&mut self, region: ByteRange) -> Result<(), ContiguousMemoryError>
pub fn take(&mut self, region: ByteRange) -> Result<(), ContiguousMemoryError>
Tries marking the provided memory region as not free, returning one
of the following errors if that’s not possible:
ContiguousMemoryError::NotContained: If the provided region falls outside of the memory tracked by theAllocationTracker.ContiguousMemoryError::AlreadyUsed: If the provided region isn’t free.
sourcepub fn take_next(
&mut self,
layout: Layout
) -> Result<ByteRange, ContiguousMemoryError>
pub fn take_next( &mut self, layout: Layout ) -> Result<ByteRange, ContiguousMemoryError>
Takes the next available memory region that can hold the provided
layout.
On success, it returns a ByteRange of the memory region that was
taken, or a ContiguousMemoryError::NoStorageLeft error if the
requested layout cannot be placed within any free regions.
sourcepub fn release(
&mut self,
region: ByteRange
) -> Result<(), ContiguousMemoryError>
pub fn release( &mut self, region: ByteRange ) -> Result<(), ContiguousMemoryError>
Tries marking the provided memory region as free, returning a
ContiguousMemoryError::NotContained error if the provided region
falls outside of the memory tracked by the AllocationTracker.
Trait Implementations§
source§impl Clone for AllocationTracker
impl Clone for AllocationTracker
source§fn clone(&self) -> AllocationTracker
fn clone(&self) -> AllocationTracker
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more