Struct slabmalloc_unsafe::ZoneAllocator 
source · pub struct ZoneAllocator<'a> {
    pub heap_id: usize,
    /* private fields */
}Expand description
A zone allocator for arbitrary sized allocations.
Has a bunch of SCAllocator and through that can serve allocation
requests for many different object sizes up to (MAX_SIZE_CLASSES) by selecting
the right SCAllocator for allocation and deallocation.
The allocator provides the refill function refill
to provide the underlying SCAllocator with more memory in case it runs out.
Fields§
§heap_id: usizeImplementations§
source§impl<'a> ZoneAllocator<'a>
 
impl<'a> ZoneAllocator<'a>
sourcepub const MAX_ALLOC_SIZE: usize = 8_104usize
 
pub const MAX_ALLOC_SIZE: usize = 8_104usize
Maximum size that allocated within 2 pages. (8 KiB - metadata) This is also the maximum object size that this allocator can handle.
sourcepub const MAX_BASE_ALLOC_SIZE: usize = 8_104usize
 
pub const MAX_BASE_ALLOC_SIZE: usize = 8_104usize
Maximum size which is allocated with ObjectPages8k (8 KiB).
e.g. this is 8 KiB - bytes of meta-data.
sourcepub const MAX_BASE_SIZE_CLASSES: usize = 11usize
 
pub const MAX_BASE_SIZE_CLASSES: usize = 11usize
How many allocators of type SCAllocator<ObjectPage8k> we have.
sourcepub const BASE_ALLOC_SIZES: [usize; 11] = _
 
pub const BASE_ALLOC_SIZES: [usize; 11] = _
The set of sizes the allocator has lists for.
pub const fn new(heap_id: usize) -> ZoneAllocator<'a>
sourcepub fn get_max_size(current_size: usize) -> Option<usize>
 
pub fn get_max_size(current_size: usize) -> Option<usize>
Return maximum size an object of size current_size can use.
Used to optimize realloc.
source§impl<'a> ZoneAllocator<'a>
 
impl<'a> ZoneAllocator<'a>
sourcepub fn retrieve_empty_page(
    &mut self,
    heap_empty_page_threshold: usize
) -> Option<&'a mut ObjectPage8k<'a>>
 
pub fn retrieve_empty_page( &mut self, heap_empty_page_threshold: usize ) -> Option<&'a mut ObjectPage8k<'a>>
Returns an ObjectPage from the SCAllocator with the maximum number of empty pages, if there are more empty pages than the threshold.
pub fn exchange_pages_within_heap( &mut self, layout: Layout ) -> Result<(), &'static str>
sourcepub fn empty_pages(&self) -> usize
 
pub fn empty_pages(&self) -> usize
The total number of empty pages in this zone allocator
sourcepub fn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, &'static str>
 
pub fn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, &'static str>
Allocate a pointer to a block of memory described by layout.
sourcepub unsafe fn deallocate(
    &mut self,
    ptr: NonNull<u8>,
    layout: Layout
) -> Result<(), &'static str>
 
pub unsafe fn deallocate( &mut self, ptr: NonNull<u8>, layout: Layout ) -> Result<(), &'static str>
Deallocates a pointer to a block of memory, which was
previously allocated by allocate.
Arguments
- ptr- Address of the memory location to free.
- layout- Memory layout of the block pointed to by- ptr.
Safety
The caller must ensure that ptr argument is returned from Self::allocate()
and layout argument is correct.