Module bump

Module bump 

Source
Expand description

Bump allocators.

Bump allocators work on a linear chunk of memory and only store a pointer where the next available byte is. New allocations are made by moving that pointer forwards, which is easy and fast. The downside is that memory cannot be freed and reused, so it should be used for short-lived programs.

§Examples

§Using an array or slice as heap

use silly_alloc::SliceBumpAllocator;

const ARENA_SIZE: usize = 64 * 1024 * 1024;
static arena: [u8; ARENA_SIZE] = [0u8; ARENA_SIZE];

#[global_allocator]
static ALLOCATOR: SliceBumpAllocator = SliceBumpAllocator::with_slice(arena.as_slice());

§Using the entire WebAssembly Memory as heap

use silly_alloc::WasmBumpAllocator;

#[global_allocator]
static ALLOCATOR: WasmBumpAllocator = WasmBumpAllocator::with_memory();

Note that WasmBumpAllocator respects the heap start address that is provided by the linker, making sure statics and other data doesn’t get corrupted by runtime allocations.

Re-exports§

pub use head::Head;
pub use head::SingleThreadedHead;
pub use head::ThreadSafeHead;

Modules§

head
Heads track where the first free byte in an arena is.

Structs§

BumpAllocator
A generic bump allocator.

Enums§

BumpAllocatorArenaError

Traits§

BumpAllocatorArena
Trait to model a consecutive chunk of linear memory for bump allocators.

Type Aliases§

BumpAllocatorArenaResult
SliceBumpAllocator
A BumpAllocator that uses the given byte slice as the arena.
ThreadsafeSliceBumpAllocator
A BumpAllocator that uses the given slice as the arena.