pub struct FixedSizeBlockAllocator { /* private fields */ }

Implementations§

source§

impl FixedSizeBlockAllocator

source

pub const fn new() -> Self

Creates an empty FixedSizeBlockAllocator.

source

pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize)

Initialize the allocator with the given heap bounds.

This function is unsafe because the caller must guarantee that the given heap bounds are valid and that the heap is unused. This method must be called only once.

source

pub unsafe fn allocate(&mut self, layout: Layout) -> *mut u8

Allocates a chunk of the given size with the given alignment. Returns a pointer to the beginning of that chunk if it was successful. Else it returns a null pointer.

Allocator first tries to find the smallest block size that is greater or equal to the required size. If a block of that size is available then it is returned, otherwise it tries to allocate from the fallback allocator.

source

pub unsafe fn deallocate(&mut self, ptr: *mut u8, layout: Layout)

Frees the given allocation. ptr must be a pointer returned by a call to the allocate function with identical size and alignment. Undefined behavior may occur for invalid arguments, thus this function is unsafe.

If the allocation returned is one of the fixed block sizes, then it is returned to the head of the block list. Otherwise, it is deallocated using the fallback allocator.

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