Module: core.memory
Source: ./core/memory.reef
Overview
core.memory - Pure Reef memory operations
Provides memory manipulation functions (memset, memcpy, memmove, memcmp) implemented entirely in Reef. Useful for freestanding environments. Also: int↔uint8 helpers (byte_from_int clamp, bytes_fill, bytes_from_ints) for safely building [byte] buffers from int data (zlib/crypto fill paths).
Functions
fn memcmp_bytes(a: [uint8], b: [uint8], n: int): int
Compares n bytes of a and b Returns: < 0 if a < b, 0 if equal, > 0 if a > b
fn byte_from_int(n: int): uint8
Clamp n to 0..255 and return as byte. Examples: byte_from_int(42) → 42, byte_from_int(300) → 255, byte_from_int(-1) → 0, byte_from_int(0) → 0, byte_from_int(255) → 255
fn byte_to_int(b: uint8): int
Widen a byte to int (0..255). Useful for comparison without unsafe at call sites.
fn bytes_from_ints(src: [int], n: int): [uint8]
Allocate an n-byte buffer and copy the first n ints from src, each clamped to 0..255 via byte_from_int. If n <= 0, returns an empty buffer. Caller must ensure src has at least n elements.
Procedures
proc memset_bytes(dest: [uint8], value: uint8, n: int)
Sets n bytes of dest to value Pure Reef implementation - operates on byte arrays
proc memcpy_bytes(dest: [uint8], src: [uint8], n: int)
Copies n bytes from src to dest WARNING: src and dest must not overlap (use memmove_bytes for overlapping)
proc memmove_bytes(dest: [uint8], src: [uint8], n: int)
Copies n bytes from src to dest (handles overlapping regions) If dest > src, copies backward to handle overlap correctly
proc memset_ints(dest: [int], value: int, n: int)
Sets n integers of dest to value
proc memcpy_ints(dest: [int], src: [int], n: int)
Copies n integers from src to dest
proc zero_bytes(dest: [uint8], n: int)
Zeros n bytes of dest
proc zero_ints(dest: [int], n: int)
Zeros n integers of dest
proc fill_bytes(dest: [uint8], value: uint8, n: int)
Fills n bytes of dest with value
proc fill_ints(dest: [int], value: int, n: int)
Fills n integers of dest with value
proc bytes_fill(dst: [uint8], start: int, len: int, value: int)
Fill dst[start .. start+len) with value clamped to 0..255. No-op when len <= 0 or start < 0. Caller must ensure start+len is within dst capacity (no runtime bounds check beyond element stores).
Generated by reefc doc