malloc

public func malloc(consuming Int64) -> RawPointer

Wraps malloc(3) — allocates size bytes of uninitialised memory.

Returns a pointer to the start of the block, or null on failure. The memory is uninitialised — read it only after writing every byte you intend to use, or follow up with memset / calloc (not exposed here). Free with free.

Safety

The returned pointer is raw. Callers are responsible for not reading uninitialised bytes, not exceeding size, and pairing every successful call with exactly one free.

Examples

let buf = malloc(1024); // ... use buf ... free(buf);

Defined in lang/std/ffi/libc.ks