std1.0.0-beta-7 SafeC docs

std :: alloc::bump

Struct std::BumpAllocator

#include <std/alloc/bump.h> source

struct BumpAllocator {
    &heap unsigned char base;
    int owned;
    unsigned long used;
    unsigned long cap;
}

Fields

§&heap unsigned char basesource

heap-backed backing buffer

§int ownedsource

1 if BumpAllocator::new allocated base (destroy() frees it)

§unsigned long usedsource

bytes currently allocated

§unsigned long capsource

total buffer capacity in bytes

Methods

§static struct BumpAllocator over([]unsigned char buffer)source · definition

An arena over an existing heap buffer of cap bytes (not freed by destroy()).

§static struct BumpAllocator new(unsigned long cap)source · definition

A heap-backed arena of cap bytes (destroy() frees it).

§?&heap unsigned char alloc(unsigned long size, unsigned long align)source · definition

Allocate size bytes whose address is a multiple of align (any power of two; 0 is taken as 1), padding the arena as needed. null when the arena is exhausted or align isn't a power of two.

§void dealloc(?&heap unsigned char ptr)source · definition

A no-op: an arena can't give back one block. reset() frees them all.

§void reset()source · definition

Reset the allocator — all previous allocations become invalid.

§unsigned long remaining() constsource · definition

Return the number of bytes still available.

§void drop()source · definition

Free the backing buffer (only valid for heap-backed allocators from BumpAllocator::new).

§void destroy() consumesource · definition

= drop()