GGUI::KeptBlocks namespace

KeptBlocks: pooled memory for things a document stores on an author's behalf (handler and component captures, ui.State values) when they don't fit inline.

Blocks come from a BufferPool (fixed size classes, lock-free, any thread), not the heap, so a document that creates and drops thousands of handlers never touches the allocator. The pool is the UI's own, separate from the buffers jobs and messages use. If a size class runs out, the block comes from the heap and is counted: nothing breaks, and the count says to grow the pool (Configure).

Classes

struct SizeClass
Blocks of one size.
struct Use
What is in use (GetUse).

Functions

auto Configure(std::span<const SizeClass> classes) -> bool
Size classes, ascending, at most eight. Only valid before first use; returns false after.
auto Take(size_t bytes) -> void*
Uninitialised memory. Any thread. Never null.
void Give(void* memory)
Return memory from Take. Any thread.
auto GetUse() -> Use
What is in use now. Any thread.
template<typename T, typename... TArgs>
auto Make(TArgs && ... args) -> T*
Construct a T in a block.
template<typename T>
void Destroy(T* made)
Destroy a T Make made, and return its block.

Variables

size_t Alignment constexpr
Block alignment.

Function documentation

bool GGUI::KeptBlocks::Configure(std::span<const SizeClass> classes)

Size classes, ascending, at most eight. Only valid before first use; returns false after.

void* GGUI::KeptBlocks::Take(size_t bytes)

Uninitialised memory. Any thread. Never null.

void GGUI::KeptBlocks::Give(void* memory)

Return memory from Take. Any thread.

Use GGUI::KeptBlocks::GetUse()

What is in use now. Any thread.

template<typename T, typename... TArgs>
T* GGUI::KeptBlocks::Make(TArgs && ... args)

Construct a T in a block.

template<typename T>
void GGUI::KeptBlocks::Destroy(T* made)

Destroy a T Make made, and return its block.

Variable documentation

size_t GGUI::KeptBlocks::Alignment constexpr

Block alignment.