API Reference › Builtin functions › bytes
function

bytes

bytes(n) -> pointer

Allocates a raw, byte-addressable buffer of n bytes and returns a pointer to its start. It is a low-level primitive used for I/O and networking scratch space — for example a buffer to serialize the world into, or to receive bytes from a socket. Size it to what you need; a common pattern is bytes(world_size()) so the buffer is exactly large enough for a full world snapshot. For a buffer of 32-bit words rather than individual bytes, use words instead.

Parameters

nthe number of bytes to allocate

Example

program SnapshotBuffer {
  property Position { column: int = 0, row: int = 0 }
  model Player { Position }

  handler Snapshot phase Start {
    spawn Player { Position { column: 3, row: 4 } }
    let buffer = bytes(world_size())
    let written = world_save(buffer)
    print(written)
  }
}
← All symbols