Heap allocation v0.1.0
Alloc
pub func Alloc(size: uint) -> *var opaque
Allocates size uninitialized bytes.
Returns the base address, or null when the size overflows the platform bookkeeping or the system cannot satisfy
the request. A zero size is permitted, but the returned address is platform-dependent and must not be touched.
The allocation is owned by the caller until Free releases it or Realloc replaces it. The address is aligned
to at least 16 bytes on every supported target.
The bytes are uninitialized. Reading any byte before writing it, accessing beyond size, or using the address
after it is released is invalid.
Parameters
| Name | Type | Description |
|---|---|---|
size | uint | how many bytes to take; zero returns null |
Returns: the address of the allocation, or null when the system refused
Free
pub func Free(ptr: *opaque)
Releases an allocation. A null pointer is accepted and does nothing.
A non-null ptr must be the live base address returned by Alloc or Realloc. Every pointer into the block
becomes invalid immediately; releasing an interior, foreign, or already released address is invalid.
Parameters
Realloc
pub func Realloc(ptr: *opaque, size: uint) -> *var opaque
Resizes an allocation to size bytes, preserving the bytes that still fit.
A null ptr behaves as Alloc(size). A zero size releases a non-null allocation and returns null. On failure,
returns null and leaves the original allocation valid; on success, the original address is invalid even when the
returned address has the same numeric value.
A non-null ptr must be the live base address returned by Alloc or an earlier Realloc. Interior, released,
or foreign addresses are invalid. Bytes added beyond the old size are uninitialized.
Parameters
| Name | Type | Description |
|---|---|---|
ptr | *opaque | the allocation to resize, or null to allocate |
size | uint | the wanted size; zero releases and returns null |
Returns: the address of the resized allocation, or null on failure