AllocablePage

Trait AllocablePage 

Source
pub trait AllocablePage {
    const SIZE: usize;

    // Required methods
    fn bitfield(&self) -> &[AtomicU64; 8];
    fn bitfield_mut(&mut self) -> &mut [AtomicU64; 8];
    fn prev(&mut self) -> &mut Rawlink<Self>
       where Self: Sized;
    fn next(&mut self) -> &mut Rawlink<Self>
       where Self: Sized;

    // Provided methods
    fn first_fit(&self, layout: Layout) -> Option<(usize, usize)> { ... }
    fn allocate(&mut self, layout: Layout) -> *mut u8 { ... }
    fn is_full(&self) -> bool { ... }
    fn is_empty(&self, relevant_bits: usize) -> bool { ... }
    fn deallocate(
        &self,
        ptr: NonNull<u8>,
        layout: Layout,
    ) -> Result<(), AllocationError> { ... }
}
Expand description

This trait is used to define a page from which objects are allocated in an SCAllocator.

The implementor of this trait needs to provide access to the page meta-data, which consists of:

  • A bitfield (to track allocations),
  • prev and next pointers to insert the page in free lists

Required Associated Constants§

Source

const SIZE: usize

The total size (in bytes) of the page.

§Note

We also assume that the address of the page will be aligned to SIZE.

Required Methods§

Source

fn bitfield(&self) -> &[AtomicU64; 8]

Source

fn bitfield_mut(&mut self) -> &mut [AtomicU64; 8]

Source

fn prev(&mut self) -> &mut Rawlink<Self>
where Self: Sized,

Source

fn next(&mut self) -> &mut Rawlink<Self>
where Self: Sized,

Provided Methods§

Source

fn first_fit(&self, layout: Layout) -> Option<(usize, usize)>

Tries to find a free block within data that satisfies alignment requirement.

Source

fn allocate(&mut self, layout: Layout) -> *mut u8

Tries to allocate an object within this page.

In case the slab is full, returns a null ptr.

Source

fn is_full(&self) -> bool

Checks if we can still allocate more objects of a given layout within the page.

Source

fn is_empty(&self, relevant_bits: usize) -> bool

Checks if the page has currently no allocations.

Source

fn deallocate( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), AllocationError>

Deallocates a memory object within this page.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> AllocablePage for LargeObjectPage<'a>

Source§

const SIZE: usize = 2_097_152usize

Source§

impl<'a> AllocablePage for ObjectPage<'a>

Source§

const SIZE: usize = 4_096usize