ChunkedRangeAlloc

Struct ChunkedRangeAlloc 

Source
pub struct ChunkedRangeAlloc { /* private fields */ }
Expand description

A simple range allocator for chunked external memory, see Self::alloc

Implementations§

Source§

impl ChunkedRangeAlloc

Source

pub fn new(chunk_size: NonZeroU32) -> Self

Constructs a new, empty ChunkedRangeAlloc with specified chunk_size

Source

pub fn from_allocations<'a>( chunk_size: NonZeroU32, allocations: impl IntoIterator<Item = &'a Allocation>, ) -> Option<Self>

Constructs ChunkedRangeAlloc with specified chunk_size and inserts allocations

Returns None if any allocation is invalid or overlaps

Source

pub fn chunk_size(&self) -> NonZeroU32

Chunk size

Source

pub fn alloc(&mut self, size: NonZeroU32, align: NonZeroU32) -> Allocation

Allocates memory with specified size and align, alignment MUST be power of two

Use NonZeroU32::MIN as align if alignment is not required

Attempts to best-fit find suitable contiguous range, otherwise creates new chunk

Caller is responsible for allocating external memory when encountering new chunk index, chunk indices are contiguous

§Panics
Source

pub fn free(&mut self, allocation: Allocation) -> bool

Frees specified allocation

Returns true if chunk with index specified in allocation becomes completely free

§Panics

Panics if allocation is invalid or double freed

Source

pub fn chunk_count(&self) -> usize

Amount of tracked chunks, both active and free/unused

Source

pub fn active_chunks(&self) -> usize

Amount of chunks containing live allocations

Source

pub fn unused_chunks(&self) -> usize

Shorthand for chunk_count() - active_chunks()

Source

pub fn capacity(&self) -> u64

Shorthand for chunk_count() * chunk_size()

Source

pub fn allocated_memory(&self) -> u64

Sum of currently allocated Allocation::lens

Source

pub fn remaining(&self) -> u64

Shorthand for capacity() - allocated_memory()

Source

pub fn used_memory(&self) -> u64

Shorthand for active_chunks() * chunk_size()

Source

pub fn unused_memory(&self) -> u64

Shorthand for used_memory() - allocated_memory()

Auto Trait Implementations§

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>,

Source§

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>,

Source§

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.