Struct good_memory_allocator::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
sourceimpl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> Allocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>where
SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,
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,
sourcepub const fn empty() -> Self
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.
sourcepub fn was_initialized(&self) -> bool
pub fn was_initialized(&self) -> bool
Checks if the heap memory region was already initialized by calling
init
.
sourcepub unsafe fn init(&mut self, heap_start_addr: usize, heap_size: usize)
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.