std1.0.0-beta-7 SafeC docs

std :: alloc::pool

Struct std::PoolAllocator

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

struct PoolAllocator {
    &heap unsigned char base;
    int owned;
    unsigned long cap;
    ?&PoolBlock head;
}

Fields

§&heap unsigned char basesource

heap-backed managed memory

§int ownedsource

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

§unsigned long capsource

total buffer size

first block in the list (walked inside unsafe)

Methods

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

A pool over a user-provided heap buffer (8-aligned) of cap bytes.

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

A heap-backed pool of cap bytes.

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

Allocate size bytes aligned to align. Every block is 8-aligned (given an 8-aligned buffer: always for PoolAllocator::new), so align is honoured up to 8 (0 is taken as 1). null if no free block fits, or align is above 8 or not a power of two.

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

Free a previously allocated pointer (null: no-op). Coalesces adjacent free blocks. Aborts with a diagnostic on a double free.

§void reset()source · definition

Free every block at once: the whole buffer is one free block again (blocks handed out before become invalid).

§unsigned long available() constsource · definition

Return total free bytes (sum of all free blocks).

§void drop()source · definition

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

§void destroy() consumesource · definition

= drop()