std1.0.0-beta-7 SafeC docs

std :: alloc::tlsf

Struct std::TlsfAllocator

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

struct TlsfAllocator {
    &heap unsigned char base;
    int owned;
    unsigned long cap;
    unsigned int fl_bitmap;
    unsigned int sl_bitmap[TLSF_FL_MAX];
    ?&TlsfBlock blocks[TLSF_FL_MAX * TLSF_SL_COUNT];
}

Fields

§&heap unsigned char basesource

heap-backed managed memory

§int ownedsource

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

§unsigned long capsource
§unsigned int fl_bitmapsource

first-level bitmap

§unsigned int sl_bitmap[TLSF_FL_MAX]source

second-level bitmaps

free-list heads

Methods

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

A TLSF allocator over a user-provided heap buffer of cap bytes.

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

A heap-backed TLSF allocator of cap bytes.

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

Allocate size bytes aligned to align. O(1). Every block is 8-aligned (given an 8-aligned buffer: always for TlsfAllocator::new), so align is honoured up to 8 (0 is taken as 1). null when 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). O(1). 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). O(1) in the block count.

§void drop()source · definition

Free the backing buffer (only valid for heap-backed allocators).

§void destroy() consumesource · definition

= drop()