Memory allocation
.malloc
C.malloc(size: num) -> ptr
Allocate memory block
Params (1)
size
Size of memory block, in bytes.
Return value
On success, a pointer to the memory block allocated by the function.
If size is zero or the function failed to allocate the requested block of memory, null is returned.
.calloc
C.calloc(count: num, size: num) -> ptr
Allocate and zero-initialize array
Params (2)
count
Number of elements to allocate.
size
Size of each element.
Return value
Like C.malloc, but the returned memory block is zero-initialized.
.realloc
C.realloc(addr: ptr, size: num) -> ptr
Reallocate memory block
Params (2)
addr
Pointer to a memory block previously allocated with C.malloc, C.calloc or C.realloc.
If this is a null pointer, the function works like C.malloc.
size
New size for the memory block, in bytes.
Return value
See C.malloc.
.free
C.free(addr: ptr)
Deallocate memory block
Parameters (1)
addr
A block of memory previously allocated by a call to C.malloc, C.calloc or C.realloc is deallocated, making it available again for further allocations.
Return value
None.
Do not free any pointer is freed or not formed by malloc, calloc and realloc.
Last updated
Was this helpful?