code wiki / (root) / nx_buf_dyn.nx

nx_buf_dyn.nx

buildroot/runtime/nx_buf_dyn.nx

5955 B199 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_buf_dyn.nx -- dynamic growable byte buffer. Every formatter / builder / ELF emitter today picks a fixed upfront cap and bails on overflow. When the cap is wrong the caller has to recompile or re-mmap. This module gives them std::vector-style amortized growth: 2x doubling when full. API: buf = nx_bd_new(initial_cap) nx_bd_byte(buf, b) nx_bd_bytes(buf, src, n) nx_bd_u32(buf, v) -- LE nx_bd_u64(buf, v) -- LE nx_bd_str(buf, s) -- NUL-terminated, NUL not written nx_bd_strz(buf, s) -- NUL-terminated, NUL written nx_bd_clear(buf) -- len=0, keeps capacity buf.buf, buf.len -- direct access for emit Growth: 2x when full, never less than +64. Old bytes are memcpy'd to the new region; the old region is leaked (we don't have munmap discipline yet, and arenas reset wholesale anyway).

dependencies 1 imports · 0 importers

syscalls.nx nx_buf_dyn.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_bd_new nx_bd_byte nx_bd_grow nx_bd_u32 nx_bd_byte ↻ nx_bd_bytes nx_bd_grow ↻ nx_bd_patch_u32 nx_bd_strz nx_bd_byte ↻ nx_bd_clear

structs

31struct NxBufDyn

consts

37const NX_BD_BYTES: i64 = 24
38const NX_BD_MIN_CAP: i64 = 64
39const NX_BD_MIN_GROW: i64 = 64

functions

41func nx_bd_new(initial_cap: i64) -> *NxBufDyn
called by 1: main
53func nx_bd_grow(b: *NxBufDyn, extra: i64) -> i64
70func nx_bd_byte(b: *NxBufDyn, v: i64) -> i64
77func nx_bd_bytes(b: *NxBufDyn, src: *u8, n: i64) -> i64
called by 1: main calls 1: nx_bd_grow
88func nx_bd_u16(b: *NxBufDyn, v: i64) -> i64
calls 1: nx_bd_byte
93func nx_bd_u32(b: *NxBufDyn, v: i64) -> i64
called by 1: main calls 1: nx_bd_byte
100func nx_bd_u64(b: *NxBufDyn, v: i64) -> i64
calls 1: nx_bd_byte
110func nx_bd_str(b: *NxBufDyn, s: *u8) -> i64
calls 1: nx_bd_byte
120func nx_bd_strz(b: *NxBufDyn, s: *u8) -> i64
called by 1: main calls 1: nx_bd_byte
129func nx_bd_clear(b: *NxBufDyn) -> i64
called by 1: main
136func nx_bd_patch_u32(b: *NxBufDyn, off: i64, v: i64) -> i64
called by 1: main
147func main() -> i64