C Memory Functions

malloc(long size): void*

Allocates a contiguous memory area with the given size in bytes. This can be used to create arrays of dynamic size. This function is slow, so it is recommended to use it for allocating memory areas in the initial run.

zalloc(long size): void*

Like malloc, but returns a pointer to a temporary memory area that is initialized to zero and preserved until the next zalloc call. This function is fast, and the memory area needs not be freed. Use this for allocating temporary arrays inside functions.


size - Size of the allocated memory area, in bytes.


void* pointer to the allocated memory area, or NULL when the allocation failed.

free(void* ptr)

Releases a contiguous memory area that was allocated with malloc.


ptr - void* pointer to the allocated memory area.

memcpy(void* dest, void* src, long size)

Copies size bytes from src to dest. Can be used to copy a whole struct or array with a single function.


dest - Target address.
src - Source address.
size - Number of bytes to copy.

memset(void* dest, int c, long size)

Sets the first size characters of dest to the character c. Can be used to initialize a whole struct or array to zero.


dest - Target address.
c - value to copy, 0..255.
size - Number of bytes to copy.



See http

See also:

sizeof, memory

► latest version online