premalloc

<alloc>
function
[defunc [premalloc [i32 size]] -> void*]
fn free(size: i32): void* {}
fn free(size: i32): void* {}

The premalloc function pre-allocates a block of memory of size bytes. The content of the newly allocated block of memory is not initialized, remaining with indeterminate values. premalloc has to be called before malloc or calloc to ensure that an end-of-memory pointer has been specified, this also makes malloc or realloc more responsive as memory can be reserved in advance.

Examples

[include "std:alloc"]

[std::premalloc 1024]
[define [void* ptr] [std::malloc 4]] // Will use memory inside the 1024 bytes allocated by premalloc
[std::free ptr]
#include "std:alloc"

std::premalloc(1024);
void* ptr = std::malloc(4); // Will use memory inside the 1024 bytes allocated by premalloc
std::free(ptr);
import malloc, free, premalloc from 'std:alloc';

premalloc(1024);
let ptr = malloc(4); // Will use memory inside the 1024 bytes allocated by premalloc
free(ptr);

See Also

alloc/malloc Allocate a block of memory.
alloc/realloc Re-allocate a block of memory.
alloc/free Releases a block of memory.