Struct slab_allocator_rs::Heap

source ·
pub struct Heap { /* private fields */ }
Expand description

A fixed size heap backed by multiple slabs with blocks of different sizes. Allocations over 4096 bytes are served by a buddy system allocator.

Implementations§

Creates a new heap with the given heap_start_addr and heap_size. The start address must be valid and the memory in the [heap_start_addr, heap_start_addr + heap_size) range must not be used for anything else.

Safety

This function is unsafe because it can cause undefined behavior if the given address is invalid.

Adds memory to the heap. The start address must be valid and the memory in the [mem_start_addr, mem_start_addr + heap_size) range must not be used for anything else. In case of buddy system allocator the memory can only be extended.

Safety

This function is unsafe because it can cause undefined behavior if the given address is invalid.

Allocates a chunk of the given size with the given alignment. Returns a pointer to the beginning of that chunk if it was successful. Else it returns (). This function finds the slab of lowest size which can still accommodate the given chunk. The runtime is in O(1) for chunks of size <= 4096, and probably fast when chunk size is > 4096,

Frees the given allocation. ptr must be a pointer returned by a call to the allocate function with identical size and alignment.

This function finds the slab which contains address of ptr and adds the blocks beginning with ptr address to the list of free blocks. This operation is in O(1) for blocks <= 4096 bytes and probably fast for blocks > 4096 bytes.

Safety

Undefined behavior may occur for invalid arguments, thus this function is unsafe.

Returns bounds on the guaranteed usable size of a successful allocation created with the specified layout.

Finds allocator to use based on layout size and alignment

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.