| malloc | Function (ROM Call 0xA2)

alloc.h, stdlib.h

void *malloc (unsigned long Size);

Allocates a memory block.

malloc allocates a block of Size bytes from the memory heap. It allows a program to allocate memory explicitly as it's needed, and in the exact amounts needed. The heap is used for dynamic allocation of variable-sized blocks of memory. Many data structures, such as trees and lists, naturally employ heap memory allocation. On success, malloc returns a pointer to the newly allocated block of memory. If not enough space exists for the new block, it returns NULL. The contents of the block are left unchanged. If the argument Size is zero malloc also returns NULL. malloc is in fact an ANSI C alias for a TIOS routine originally called HeapAllocPtr (see description of it for more system info).
Note: As the TIOS memory manager assigns a handle to each allocated block, and as the total number of handles is limited, malloc is not good for algorithms where you need to allocate a large number of small blocks (as in implementations of linked lists which are usually seen in various C language books and tutorials). The same is true for all other TIOS memory management routines.

Uses: HeapAllocHigh, NeedStack
Used by: malloc_throw

See also: realloc, calloc, free, malloc_throw