Struct slabmalloc::ZoneAllocator
source · [−]pub struct ZoneAllocator<'a> { /* 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 to refill functions refill
and refill_large
to provide the underlying SCAllocator
with more memory in case it runs out.
Implementations
sourceimpl<'a> ZoneAllocator<'a>
impl<'a> ZoneAllocator<'a>
sourcepub const MAX_ALLOC_SIZE: usize = 131_072usize
pub const MAX_ALLOC_SIZE: usize = 131_072usize
Maximum size that allocated within LargeObjectPages (2 MiB). This is also the maximum object size that this allocator can handle.
sourcepub const MAX_BASE_ALLOC_SIZE: usize = 256usize
pub const MAX_BASE_ALLOC_SIZE: usize = 256usize
Maximum size which is allocated with ObjectPages (4 KiB pages).
e.g. this is 4 KiB - 80 bytes of meta-data.
pub const fn new() -> 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
.
sourcepub fn try_reclaim_base_pages<F>(&mut self, to_reclaim: usize, dealloc: F) where
F: Fn(*mut ObjectPage<'_>),
pub fn try_reclaim_base_pages<F>(&mut self, to_reclaim: usize, dealloc: F) where
F: Fn(*mut ObjectPage<'_>),
Reclaims empty pages by calling dealloc
on it and removing it from the
empty lists in the SCAllocator
.
The dealloc
function is called at most reclaim_base_max
times for
base pages, and at most reclaim_large_max
for large pages.
sourcepub fn try_reclaim_large_pages<F>(&mut self, to_reclaim: usize, dealloc: F) where
F: FnMut(*mut LargeObjectPage<'_>),
pub fn try_reclaim_large_pages<F>(&mut self, to_reclaim: usize, dealloc: F) where
F: FnMut(*mut LargeObjectPage<'_>),
Reclaims empty pages by calling dealloc
on it and removing it from the
empty lists in the SCAllocator
.
The dealloc
function is called at most reclaim_base_max
times for
base pages, and at most reclaim_large_max
for large pages.
Trait Implementations
sourceimpl<'a> Allocator<'a> for ZoneAllocator<'a>
impl<'a> Allocator<'a> for ZoneAllocator<'a>
sourcefn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocationError>
fn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocationError>
Allocate a pointer to a block of memory described by layout
.
sourcefn deallocate(
&mut self,
ptr: NonNull<u8>,
layout: Layout
) -> Result<(), AllocationError>
fn deallocate(
&mut self,
ptr: NonNull<u8>,
layout: Layout
) -> Result<(), AllocationError>
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 byptr
.
sourceunsafe fn refill(
&mut self,
layout: Layout,
new_page: &'a mut ObjectPage<'a>
) -> Result<(), AllocationError>
unsafe fn refill(
&mut self,
layout: Layout,
new_page: &'a mut ObjectPage<'a>
) -> Result<(), AllocationError>
Refills the SCAllocator for a given Layout with an ObjectPage.
Safety
ObjectPage needs to be emtpy etc.
sourceunsafe fn refill_large(
&mut self,
layout: Layout,
new_page: &'a mut LargeObjectPage<'a>
) -> Result<(), AllocationError>
unsafe fn refill_large(
&mut self,
layout: Layout,
new_page: &'a mut LargeObjectPage<'a>
) -> Result<(), AllocationError>
Refills the SCAllocator for a given Layout with an ObjectPage.
Safety
ObjectPage needs to be emtpy etc.
sourceimpl<'a> Default for ZoneAllocator<'a>
impl<'a> Default for ZoneAllocator<'a>
sourcefn default() -> ZoneAllocator<'a>
fn default() -> ZoneAllocator<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl<'a> RefUnwindSafe for ZoneAllocator<'a>
impl<'a> Send for ZoneAllocator<'a>
impl<'a> Sync for ZoneAllocator<'a>
impl<'a> Unpin for ZoneAllocator<'a>
impl<'a> !UnwindSafe for ZoneAllocator<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more