nx_buf_dyn_owned_candidate_t218.nx
buildroot/runtime/nx_buf_dyn_owned_candidate_t218.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 · 2 importers
imports: syscalls.nx
imported by: nx_buf_owned_gate_t218.nxnx_tool_run_owned_candidate_t218.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 31 | struct NxBufDyn |
| 205 | struct NxBufOwned { buf:*u8, len:i64, cap:i64, } |
consts
| 37 | const NX_BD_BYTES: i64 = 24 |
| 38 | const NX_BD_MIN_CAP: i64 = 64 |
| 39 | const NX_BD_MIN_GROW: i64 = 64 |
| 206 | const NX_BO_BYTES:i64=24 |
| 207 | const NX_BO_I64_MAX:i64=9223372036854775807 |
| 208 | const NX_BO_INVALID:i64=-100 |
| 209 | const NX_BO_RANGE:i64=-101 |
| 210 | const NX_BO_CAPACITY:i64=-102 |
| 211 | const NX_BO_ALLOCATION:i64=-103 |
| 212 | const NX_BO_ALIAS:i64=-104 |
| 213 | const NX_BO_RELEASE:i64=-105 |
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 |
| 214 | func nx_bo_state(b:*NxBufOwned)->i64 |
| 221 | func nx_bo_append(b:*NxBufOwned,src:*u8,n:i64,max_bytes:i64)->i64 |
| 243 | func nx_bo_release(b:*NxBufOwned)->i64 |