pub struct GlobalChunkAllocator<'a, const CHUNK_SIZE: usize = DEFAULT_CHUNK_SIZE>(_);
Expand description

Synchronized high-level wrapper around ChunkAllocator that implements the Rust traits GlobalAlloc which enables the usage as global allocator. The method GlobalChunkAllocator::allocator_api_glue returns an object of type AllocatorApiGlue which can be used with the allocator_api feature.

#![feature(const_mut_refs)]

use simple_chunk_allocator::{heap, heap_bitmap, GlobalChunkAllocator, PageAligned};

// The macros help to get a correctly sized arrays types.
// I page-align them for better caching and to improve the availability of
// page-aligned addresses.

/// Backing storage for heap (1Mib). (read+write) static memory in final executable.
static mut HEAP: PageAligned<[u8; 1048576]> = heap!();
/// Backing storage for heap bookkeeping bitmap. (read+write) static memory in final executable.
static mut HEAP_BITMAP: PageAligned<[u8; 512]> = heap_bitmap!();

#[global_allocator]
static ALLOCATOR: GlobalChunkAllocator =
    unsafe { GlobalChunkAllocator::new(HEAP.deref_mut_const(), HEAP_BITMAP.deref_mut_const()) };

Implementations

High-level constructor around ChunkAllocator::<CHUNK_SIZE>::new_const.

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.

Returns the usage of the allocator in percentage.

Returns an instance of AllocatorApiGlue.

Trait Implementations

Formats the value using the given formatter. Read more

Allocate memory as described by the given layout. Read more

Deallocate the block of memory at the given ptr pointer with the given layout. Read more

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more

Shrink or grow a block of memory to the given new_size. The block is described by the given ptr pointer and layout. 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.