nx_buf_dyn.nx
buildroot/runtime/nx_buf_dyn.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 31 | struct NxBufDyn |
consts
| 37 | const NX_BD_BYTES: i64 = 24 |
| 38 | const NX_BD_MIN_CAP: i64 = 64 |
| 39 | const NX_BD_MIN_GROW: i64 = 64 |
functions
| 41 | func nx_bd_new(initial_cap: i64) -> *NxBufDyn called by 1: main |
| 53 | func nx_bd_grow(b: *NxBufDyn, extra: i64) -> i64 |
| 70 | func nx_bd_byte(b: *NxBufDyn, v: i64) -> i64 |
| 77 | func nx_bd_bytes(b: *NxBufDyn, src: *u8, n: i64) -> i64 |
| 88 | func nx_bd_u16(b: *NxBufDyn, v: i64) -> i64 calls 1: nx_bd_byte |
| 93 | func nx_bd_u32(b: *NxBufDyn, v: i64) -> i64 |
| 100 | func nx_bd_u64(b: *NxBufDyn, v: i64) -> i64 calls 1: nx_bd_byte |
| 110 | func nx_bd_str(b: *NxBufDyn, s: *u8) -> i64 calls 1: nx_bd_byte |
| 120 | func nx_bd_strz(b: *NxBufDyn, s: *u8) -> i64 |
| 129 | func nx_bd_clear(b: *NxBufDyn) -> i64 called by 1: main |
| 136 | func nx_bd_patch_u32(b: *NxBufDyn, off: i64, v: i64) -> i64 called by 1: main |
| 147 | func main() -> i64 |