Struct offset_allocator::Allocator

source ·
pub struct Allocator<NI = u32>
where NI: NodeIndex,
{ /* private fields */ }
Expand description

An allocator that manages a single contiguous chunk of space and hands out portions of it as requested.

Implementations§

source§

impl<NI> Allocator<NI>
where NI: NodeIndex,

source

pub fn new(size: u32) -> Self

Creates a new allocator, managing a contiguous block of memory of size units, with a default reasonable number of maximum allocations.

source

pub fn with_max_allocs(size: u32, max_allocs: u32) -> Self

Creates a new allocator, managing a contiguous block of memory of size units, with the given number of maximum allocations.

Note that the maximum number of allocations must be less than NodeIndex::MAX minus one. If this restriction is violated, this constructor will panic.

source

pub fn reset(&mut self)

Clears out all allocations.

source

pub fn allocate(&mut self, size: u32) -> Option<Allocation<NI>>

Allocates a block of size elements and returns its allocation.

If there’s not enough contiguous space for this allocation, returns None.

source

pub fn free(&mut self, allocation: Allocation<NI>)

Frees an allocation, returning the data to the heap.

If the allocation has already been freed, the behavior is unspecified. It may or may not panic. Note that, because this crate contains no unsafe code, the memory safe of the allocator itself will be uncompromised, even on double free.

source

pub fn allocation_size(&self, allocation: Allocation<NI>) -> u32

Returns the used size of an allocation.

Note that this may be larger than the size requested at allocation time, due to rounding.

source

pub fn storage_report(&self) -> StorageReport

Returns a structure containing the amount of free space remaining, as well as the largest amount that can be allocated at once.

source

pub fn storage_report_full(&self) -> StorageReportFull

Returns detailed information about the number of allocations in each bin.

Trait Implementations§

source§

impl<NI> Debug for Allocator<NI>
where NI: NodeIndex,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<NI> Freeze for Allocator<NI>
where <NI as NodeIndex>::NonMax: Freeze,

§

impl<NI> RefUnwindSafe for Allocator<NI>
where <NI as NodeIndex>::NonMax: RefUnwindSafe,

§

impl<NI> Send for Allocator<NI>
where <NI as NodeIndex>::NonMax: Send,

§

impl<NI> Sync for Allocator<NI>
where <NI as NodeIndex>::NonMax: Sync,

§

impl<NI> Unpin for Allocator<NI>
where <NI as NodeIndex>::NonMax: Unpin,

§

impl<NI> UnwindSafe for Allocator<NI>
where <NI as NodeIndex>::NonMax: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where 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 T
where 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.