pub struct ChunkAllocator<'a, const CHUNK_SIZE: usize = DEFAULT_CHUNK_SIZE> { /* private fields */ }
Expand description

Low-level chunk allocator that operates on the provided backing memory. Allocates memory with a variant of the strategies next-fit and best-fit.

The default chunk size is DEFAULT_CHUNK_SIZE. A large chunk size has the negative impact that small allocations will consume at least one chunk. A small chunk size has the negative impact that the allocation may take slightly longer.

Implementations

Returns the used chunk size.

Returns the minimum guaranteed alignment by the allocator per chunk. A chunk will never be at an address like 0x13, i.e., unaligned.

Creates a new allocator object. Verifies that the provided memory has the correct properties. Zeroes the bitmap.

  • heap length must be a multiple of CHUNK_SIZE
  • the heap must be not empty
  • the bitmap must match the number of chunks
  • the heap must be at least aligned to CHUNK_SIZE.

It is recommended that the heap and the bitmap both start at page-aligned addresses for better performance and to enable a faster search for correctly aligned addresses.

WARNING: During const initialization it is not possible to check the alignment of the provided buffer. Please make sure that the data is at least aligned to the chunk_size. The recommended alignment is page-alignment.

Version of Self::new that panics instead of returning a result. Useful for globally static const contexts. The panic will happen during compile time and not during run time. Self::new can’t be used in such scenarios because unwrap() on the Result is not a const function (yet).

WARNING: During const initialization it is not possible to check the alignment of the provided buffer. Please make sure that the data is at least aligned to the chunk_size. The recommended alignment is page-alignment.

Capacity in bytes of the allocator.

Returns number of chunks.

Returns the current memory usage in percentage rounded to two decimal places.

Safety

Unsafe if memory gets de-allocated that is still in use.

Trait Implementations

Formats the value using the given formatter. Read more

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.