pub struct AllocationTracker { /* private fields */ }
Expand description

A structure that keeps track of unused regions of memory within provided bounds.

Implementations§

source§

impl AllocationTracker

source

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.
source

pub fn len(&self) -> usize

Returns the total memory size being tracked.

source

pub fn is_empty(&self) -> bool

Checks if there is no empty space left in the tracked region.

source

pub fn whole_range(&self) -> ByteRange

Returns a ByteRange encompassing the entire tracked memory region.

source

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.

source

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.

source

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.

source

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:

source

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.

source

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

source§

fn clone(&self) -> AllocationTracker

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.