Struct Allocator

Source
pub struct Allocator<const SMALLBINS_AMOUNT: usize = DEFAULT_SMALLBINS_AMOUNT, const ALIGNMENT_SUB_BINS_AMOUNT: usize = DEFAULT_ALIGNMENT_SUB_BINS_AMOUNT>
where SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,
{ /* private fields */ }
Expand description

A linked list memory allocator.

This allocator allows configuring the amount of smallbins and alignment sub-bins that it uses. For more information about this value, read the crate’s top level documentation.

Implementations§

Source§

impl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>
where SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,

Source

pub const fn empty() -> Self

Creates an empty heap allocator without any heap memory region, which will always return null on allocation requests.

To intiialize this allocator, use the init method.

Source

pub fn was_initialized(&self) -> bool

Checks if the heap memory region was already initialized by calling init.

Source

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

Initializes the heap allocator with the given memory region.

§Safety

If the allocator was already initialized, this function will panic.

The Allocator on which this was called must not be moved, and its address in memory must not change, otherwise undefined behaviour will occur. This is because the heap region now contains pointers to fields of this struct, and if this struct will move, the address of its fields will change, and those pointers will now be invalid.

The provided memory region must be valid and non-null, and must not be used by anything else.

If after aligning the start and end addresses, the size of the heap is 0, the function panics.

Source

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

Allocates memory.

Source

pub unsafe fn dealloc(&mut self, ptr: *mut u8)

Deallocates memory.

Source

pub unsafe fn realloc( &mut self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Resizes an allocation previously returned from alloc or realloc. The alignment of the content will stay the same.

Trait Implementations§

Source§

impl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> Debug for Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>
where SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> Send for Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>
where SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,

Auto Trait Implementations§

§

impl<const SMALLBINS_AMOUNT: usize = DEFAULT_SMALLBINS_AMOUNT, const ALIGNMENT_SUB_BINS_AMOUNT: usize = DEFAULT_ALIGNMENT_SUB_BINS_AMOUNT> !Freeze for Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>

§

impl<const SMALLBINS_AMOUNT: usize = DEFAULT_SMALLBINS_AMOUNT, const ALIGNMENT_SUB_BINS_AMOUNT: usize = DEFAULT_ALIGNMENT_SUB_BINS_AMOUNT> !RefUnwindSafe for Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>

§

impl<const SMALLBINS_AMOUNT: usize = DEFAULT_SMALLBINS_AMOUNT, const ALIGNMENT_SUB_BINS_AMOUNT: usize = DEFAULT_ALIGNMENT_SUB_BINS_AMOUNT> !Sync for Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>

§

impl<const SMALLBINS_AMOUNT: usize = DEFAULT_SMALLBINS_AMOUNT, const ALIGNMENT_SUB_BINS_AMOUNT: usize = DEFAULT_ALIGNMENT_SUB_BINS_AMOUNT> !Unpin for Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>

§

impl<const SMALLBINS_AMOUNT: usize = DEFAULT_SMALLBINS_AMOUNT, const ALIGNMENT_SUB_BINS_AMOUNT: usize = DEFAULT_ALIGNMENT_SUB_BINS_AMOUNT> !UnwindSafe for Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>

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.