Struct alloc_buddy_simple::Heap [] [src]

pub struct Heap<'a> { /* fields omitted */ }

The interface to a heap. This data structure is stored outside the heap somewhere, because every single byte of our heap is potentially available for allocation.

Methods

impl<'a> Heap<'a>
[src]

Create a new heap. heap_base must be aligned on a MIN_HEAP_ALIGN boundary, heap_size must be a power of 2, and heap_size / 2.pow(free_lists.len()-1) must be greater than or equal to size_of::<FreeBlock>(). Passing in invalid parameters may do horrible things.

Figure out what size block we'll need to fulfill an allocation request. This is deterministic, and it does not depend on what we've already allocated. In particular, it's important to be able to calculate the same allocation_size when freeing memory as we did when allocating it, or everything will break horribly.

The "order" of an allocation is how many times we need to double min_block_size in order to get a large enough block, as well as the index we use into free_lists.

Allocate a block of memory large enough to contain size bytes, and aligned on align. This will return NULL if the align is greater than MIN_HEAP_ALIGN, if align is not a power of 2, or if we can't find enough memory.

All allocated memory must be passed to deallocate with the same size and align parameter, or else horrible things will happen.

Given a block with the specified order, find the "buddy" block, that is, the other half of the block we originally split it from, and also the block we could potentially merge it with.

Deallocate a block allocated using allocate. Note that the old_size and align values must match the values passed to allocate, or our heap will be corrupted.

Trait Implementations

impl<'a> Send for Heap<'a>
[src]