[][src]Struct basic_allocator::blocklist::BlockList

pub struct BlockList { /* fields omitted */ }

A BlockList is a linked list of "free" blocks in memory.

Each block should be considered "owned" by the BlockList when inserted, and do not hold any sort of payload. They may be split or merged internally.

In this module, thse memory blocks represent freed memory that has not been returned to the OS, and provide a "pool" of available memory for reuse by the allocator.

It maintains a few internal invariants:

  • Each block should link to the next, with the last one linking to null.
  • Each block should have a pointer < next.
  • No two blocks should be precisely adjacent (those should be automatically merged on insertion).

Implementations

impl BlockList[src]

pub const fn header_size() -> usize[src]

pub fn iter(&self) -> BlockIter

Important traits for BlockIter<'list>

impl<'list> Iterator for BlockIter<'list> type Item = &'list FreeBlock;
[src]

pub fn apply<C, R, F: FnMut(&mut FreeBlock, C) -> ApplyState<C, R>>(
    &mut self,
    start: C,
    pred: F
) -> ApplyState<C, R>
[src]

Iterate through the blocklist, and apply a function at each step. This allows mutating the list as it is traversed, and replaces IterMut, which cannot be used due to the links between blocks.

Note that any changes to any block's "next" will be followed at the next iteration.

pub fn stats(&self) -> (Validity, Stats)[src]

Check current size of the list, and whether its valid.

pub fn pop_size(&mut self, size: usize) -> Option<Range<NonNull<u8>>>[src]

Find and remove a chunk of size 'size' from the linked list

pub unsafe fn add_block(&mut self, ptr: NonNull<u8>, size: usize)[src]

Add a block to the linked list. Takes ownership of ptr.

Safety

ptr must point to valid, reachable memory of at least size, and ownership of that memory must be transferred to BlockList when this method is called.

pub fn len(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

Trait Implementations

impl Default for BlockList[src]

impl Display for BlockList[src]

impl<'list> IntoIterator for &'list BlockList[src]

type Item = &'list FreeBlock

The type of the elements being iterated over.

type IntoIter = BlockIter<'list>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl Send for BlockList

impl !Sync for BlockList

impl Unpin for BlockList

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.