Introduction

For managing dynamically allocated memory, the standard C library provides the functions malloc(), calloc(), realloc() and free(). In C99 and later, there is also aligned_alloc(). Some systems also provide alloca().

Syntax

Parameters

name | description |

|———|––––––––| | size (malloc, realloc and aligned_alloc) | total size of the memory in bytes. For aligned_alloc the size must be a integral multiple of alignment. | | size (calloc) | size of each element | | nelements | number of elements | | ptr | pointer to allocated memory previously returned by malloc, calloc, realloc or aligned_alloc | | alignment | alignment of allocated memory

Remarks

Note that aligned_alloc() is only defined for C11 or later.

Systems such as those based on POSIX provide other ways of allocating aligned memory (e.g. [posix_memalign()](<http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html>)), and also have other memory management options (e.g. [mmap()](<http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html>)).