pub struct ZoneAllocator {
    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 memory.

Fields§

§heap_id: usize

Implementations§

source§

impl ZoneAllocator

source

pub const MAX_ALLOC_SIZE: usize = 8_112usize

Maximum size that allocated within 2 pages. (8 KiB - metadata) This is also the maximum object size that this allocator can handle.

source

pub const MAX_BASE_ALLOC_SIZE: usize = 8_112usize

Maximum size which is allocated with ObjectPages8k (8 KiB).

e.g. this is 8 KiB - bytes of meta-data.

source

pub const MAX_BASE_SIZE_CLASSES: usize = 11usize

How many allocators of type SCAllocator we have.

source

pub const BASE_ALLOC_SIZES: [usize; 11] = _

The set of sizes the allocator has lists for.

source

pub fn new(heap_id: usize) -> ZoneAllocator

source

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 ZoneAllocator

source

pub fn retrieve_empty_page( &mut self, heap_empty_page_threshold: usize ) -> Option<MappedPages8k>

Returns a MappedPages8k from the SCAllocator with the maximum number of empty pages, if there are more empty pages than the threshold.

source

pub fn exchange_pages_within_heap( &mut self, layout: Layout ) -> Result<(), &'static str>

source

pub fn empty_pages(&self) -> usize

The total number of empty pages in this zone allocator

source

pub fn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, &'static str>

Allocate a pointer to a block of memory described by layout.

source

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.

source

pub fn refill( &mut self, layout: Layout, mp: MappedPages8k ) -> Result<(), &'static str>

Refills the SCAllocator for a given Layout with a MappedPages8k.

Safety

MappedPages should not be in use by any other heap.

Trait Implementations§

source§

impl Default for ZoneAllocator

source§

fn default() -> ZoneAllocator

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.