|
|
#include <stdlib.h>void *malloc(size_t size);
The malloc( ) function returns a pointer to the first byte of a region of memory of size size that has been allocated from the heap. If there is insufficient memory in the heap to satisfy the request, malloc( ) returns a null pointer. It is always important to verify that the return value is not null before attempting to use it. Attempting to use a null pointer will usually result in a system crash.
Related functions are free( ), realloc( ), and calloc( ).
Programming Tip | If you are writing 16-bit programs for the 8086 family of processors, then your compiler will provide additional allocation functions that accommodate the segmented memory used by these processors when operating in 16-bit mode. For example, there will be functions that allocate memory from the FAR heap (the heap that is outside the default data segment), that can allocate pointers to memory that is larger than one segment, and that free such memory. |
|
|