Example: mallocMemory Allocation Functions

Allocates a block of memory.

void *malloc( size_t num_bytes); 

num_bytesThe size of the block of memory that is allocated.

Return Values

Returns a void type pointer to the allocated space. If the system could not allocate the requested block of memory or if num_bytes is 0, returns a NULL pointer.

You must free the memory when you are finished with it: free(bufferPointer);

If you try to create a local variable that is too large or if the total size of the local variables is to large, the C interpreter throws an error "Too many local variables" instead of indicating that the buffer is too large. For example, this is an error: char buffer[4096*8];.

To allocate large buffers, use malloc instead of declaring the buffer as a local variable.</p>

For malloc details, refer to your C language documentation.