Struct FixedSizeAllocator

Source
pub struct FixedSizeAllocator<const S: usize, const N: usize> { /* private fields */ }

Implementations§

Source§

impl<const S: usize, const N: usize> FixedSizeAllocator<S, N>
where Assert<{ _ }>: IsTrue,

Source

pub unsafe fn new_unpinned(zero_initialized: bool) -> Self

Construct a new fixed-size allocator on the stack and return it. Optionally, you can initialize the heap with 0 bytes by setting the zero_initialized flag. !This doesn’t mean that the allocator is initialized! The returned allocator struct must immediately be pinned via pin!(). Using an unpinned allocator created on the stack is undefined behavior. This function is marked as unsafe because it’s the programmer’s responsibility to correctly instantiate and pin an allocator on the stack.

Source

pub fn new(zero_initialized: bool) -> Pin<Box<Self>>

Create a new fixed-size allocator on the heap using the standard system allocator. Optionally, you can initialize the heap with 0 bytes by setting the zero_initialized flag. Note that the returned allocator is pinned, meaning it cannot be moved once it’s created. This is why a Pin<Box<>> is returned instead.

Source

pub const fn heap_size(&self) -> usize

Return the total size of the heap in bytes.

Source

pub const fn block_count(&self) -> usize

Return the total number of memory blocks.

Source

pub const fn block_size(&self) -> usize

Return the size of a memory block.

Source

pub const fn total_free(&self) -> usize

Return the total amount of free memory in bytes.

Source

pub const fn total_allocated(&self) -> usize

Return the total amount of memory allocated in bytes.

Source

pub fn free_blocks(&self) -> usize

Return how many blocks are free.

Source

pub fn allocated_blocks(&self) -> usize

Return how many blocks are allocated (not free).

Source

pub unsafe fn alloc_untyped(self: Pin<&mut Self>) -> Option<NonNull<u8>>

Source

pub fn alloc<T>(self: Pin<&mut Self>) -> Option<NonNull<T>>
where Assert<{ _ }>: IsTrue,

Try to allocate a memory block of that fits T, where T is S-sized.

Source

pub fn free_nonnull<T>( self: Pin<&mut Self>, ptr: NonNull<T>, ) -> Result<(), FreeError>

Free the given non-null pointer. Note that the pointer must be aligned to the block’s start address.

Source

pub fn free<T>(self: Pin<&mut Self>, ptr: *const T) -> Result<(), FreeError>

Free the given pointer. Note that the pointer must be aligned to the block’s start address.

Source

pub unsafe fn free_all(self: Pin<&mut Self>)

Free all the memory blocks. This function is inherently unsafe because it invalidates all pointers to previously allocated blocks.

Auto Trait Implementations§

§

impl<const S: usize, const N: usize> Freeze for FixedSizeAllocator<S, N>

§

impl<const S: usize, const N: usize> RefUnwindSafe for FixedSizeAllocator<S, N>

§

impl<const S: usize, const N: usize> Send for FixedSizeAllocator<S, N>

§

impl<const S: usize, const N: usize> Sync for FixedSizeAllocator<S, N>

§

impl<const S: usize, const N: usize> !Unpin for FixedSizeAllocator<S, N>

§

impl<const S: usize, const N: usize> UnwindSafe for FixedSizeAllocator<S, N>

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.