nupp.mem
C storage, and the checked views that make a raw pointer safe to index.
Nothing is re-exported here: every member is a module of its own, reached by the name it has.
const span = require("nupp.mem.span")
local struct Point
x: number
y: number
end
const storage = carray(Point, 4)
const points = span.fromCarray(storage, 4)
print(points[1].x)nupp.mem.span-- borrowed views over storage rooted by another value.nupp.mem.array-- owned contiguous arrays, native and Wasm.nupp.mem.heap-- owned malloc-backed arrays.nupp.mem.soa-- structure-of-arrays storage.nupp.mem.indexed-- the one inclusive range they all validate against.nupp.mem.arena-- leases zero-filled struct rows from pages that never move, so it hands storage out and takes it back rather than viewing it.
A view knows its element count, and every index and slice is checked against it before the only unsafe pointer arithmetic in the standard library. Record instances backed by a Lua table are nupp.util.Pool instead, which needs no C storage and so lives with the general-purpose types.
See c-interop.md for what crossing the C boundary costs, and ownership.md for the borrow rules these views are written against.
Submodules
| Module | Description |
|---|---|
nupp.mem.arena | A paged allocator of struct rows whose pages never move. |
nupp.mem.array | Owned contiguous arrays of one scalar or struct type. |
nupp.mem.heap | Owned, malloc-backed C arrays. |
nupp.mem.indexed | One inclusive range, checked once against every view a loop is about to index. |
nupp.mem.representation | |
nupp.mem.sharedbytes | Engine-owned immutable byte regions. |
nupp.mem.soa | Structure-of-arrays storage for reified structs. |
nupp.mem.span | nupp.mem.span gives a C array a rooted, one-based, bounds-checked view. |