previous | start | next

malloc and free

The memory map function is one way to dynamically create a new chunk of memory (as a program is running) as a new virtual memory segment.

More commonly applications have (and continue to) use functions malloc and free (or new and delete) to dynamically allocate memory from the heap segment.

#include <stdlib.h>

void *calloc(size_t nmemb, size_t sz);
void *malloc(size_t sz);
void free(void *ptr);
void *realloc(void *ptr, size_t sz);

The memory allocation functions (calloc, malloc, and realloc) all simply specify a size (in bytes) or in the case of calloc, an array of nmemb elements, each of size sz.



previous | start | next