realloc

public func realloc(consuming RawPointer, consuming Int64) -> RawPointer

Wraps realloc(3) — resizes a previously-malloc'd block.

May return the same pointer or a new one; either way, the original pointer becomes invalid. Returns null on failure, in which case the original block is not freed — capture the return value before reassigning. Bytes beyond the old size in a grown block are uninitialised.

Safety

ptr must be null or a pointer from a previous malloc / realloc. After a successful call, only the returned pointer is valid; after a failed call, only the original pointer is valid.

Examples

var buf = malloc(64); let bigger = realloc(buf, 256); // buf is no longer valid; use bigger

Defined in lang/std/ffi/libc.ks