|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Heap-free scratch allocator for stb_truetype (glyph rasterise). More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Functions | |
| void * | ra8_stbtt_malloc (size_t n) |
| Allocate n bytes of glyph scratch from the static arena. | |
| void | ra8_stbtt_free (void *p) |
| Release a block previously returned by ra8_stbtt_malloc(). | |
| size_t | ra8_stbtt_alloc_high_water (void) |
| Worst-case arena high-water mark observed since boot, in bytes. | |
Heap-free scratch allocator for stb_truetype (glyph rasterise).
stb_truetype allocates short-lived scratch (glyph vertices, rasteriser edge/point lists) through STBTT_malloc / STBTT_free for every glyph – on both the one-shot stbtt_GetCodepointBitmap() path and the two-step stbtt_GetCodepointBitmapBox() + stbtt_MakeCodepointBitmap() path. The firmware has no heap (_sbrk traps after init), so the build redirects those macros to the functions below (see the CMake STBTT_malloc / STBTT_free compile definitions on the stb_truetype_impl.c source).
The allocator is a fixed-capacity bump arena with reference-counted auto-reset: each successful ra8_stbtt_malloc() bumps an offset and a live-block count; each ra8_stbtt_free() decrements the count and, when it reaches zero, rewinds the offset to the base. Every top-level stb_truetype call frees all of its scratch before returning, so the arena fully drains after each glyph – no caller cooperation, robust to any free order (stb frees composite-glyph buffers out of LIFO order), and immune to fragmentation. On exhaustion ra8_stbtt_malloc() returns NULL; stb_truetype tolerates this and the offending glyph is skipped rather than corrupting memory.
NASA Power-of-10 Rule 3 (no dynamic allocation after init): the backing store is a single file-scope array.
[Ring 4 / Reflow] {World: NS}
Definition in file ra8_stbtt_alloc.h.
| size_t ra8_stbtt_alloc_high_water | ( | void | ) |
Worst-case arena high-water mark observed since boot, in bytes.
Diagnostic hook for sizing/regression: lets a host test or an on-target probe confirm the configured capacity has headroom.
| 0 | No allocation has been made yet. |
Definition at line 83 of file ra8_stbtt_alloc.c.
References s_high_water.
| void ra8_stbtt_free | ( | void * | p | ) |
Release a block previously returned by ra8_stbtt_malloc().
Decrements the live-block count; the bump offset is not tracked per block. When the count reaches zero the arena is fully drained, so the offset rewinds to the base. A nullptr argument is ignored.
| [in] | p | Pointer to release; nullptr is ignored. |
Definition at line 70 of file ra8_stbtt_alloc.c.
| void * ra8_stbtt_malloc | ( | size_t | n | ) |
Allocate n bytes of glyph scratch from the static arena.
Bumps the arena offset by n rounded up to the 16-byte alignment and increments the live-block count. Requests larger than the arena, or that do not fit the remaining capacity, fail with nullptr.
| [in] | n | Byte count requested by stb_truetype. |
| nullptr | The request exceeds the arena or remaining capacity. |
Definition at line 50 of file ra8_stbtt_alloc.c.
References k_ra8_stbtt_align_mask, k_ra8_stbtt_arena_bytes, s_arena, s_high_water, s_live, and s_offset.