pub struct SpinLockedAllocator<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;
Expand description
A spin locked memory allocator that can be used as the global allocator.
Implementations
sourceimpl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> SpinLockedAllocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>where
SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,
impl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> SpinLockedAllocator<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 locked heap allocator without any heap memory region, which will always return null on allocation requests.
To intiialize this allocator, use the init
method.
sourcepub unsafe fn init(&self, heap_start_addr: usize, heap_size: usize)
pub unsafe fn init(&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 SpinLockedAllocator
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.
sourcepub fn was_initialized(&self) -> bool
pub fn was_initialized(&self) -> bool
Checks if the heap memory region was already initialized by calling init.
Trait Implementations
sourceimpl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> GlobalAlloc for SpinLockedAllocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>where
SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,
impl<const SMALLBINS_AMOUNT: usize, const ALIGNMENT_SUB_BINS_AMOUNT: usize> GlobalAlloc for SpinLockedAllocator<SMALLBINS_AMOUNT, ALIGNMENT_SUB_BINS_AMOUNT>where
SmallestTypeWhichHasAtLeastNBitsStruct<ALIGNMENT_SUB_BINS_AMOUNT>: SmallestTypeWhichHasAtLeastNBitsTrait,
sourceunsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout
. Read more