| manpages.info - online man pages | ![]() |
|||
|
free (3) Table of Contents
Namemalloc, calloc, valloc, realloc, free, malloc_size, malloc_good_size memory allocation
Synopsis#include <stdlib.h>
void *
void *
void *
void *
void
size_t
size_t
DescriptionThe malloc(), calloc(), valloc(), and realloc() functions allocate memory. The allocated memory is aligned such that it can be used for any data type, including AltiVec-related types. The free() function frees allocations that were created via the preceding allocation functions. The malloc_size() and malloc_good_size() functions provide information related to the amount of padding space at the end of allocations.
The malloc() function allocates size bytes of memory and returns a pointer to the allocated memory. malloc() returns a NULL pointer if there is an error.
The calloc() function contiguously allocates enough space for count objects that are size bytes of memory each and returns a pointer to the allocated memory. The allocated memory is filled with bytes of value zero. calloc() returns a NULL pointer if there is an error.
The valloc() function allocates size bytes of memory and returns a pointer to the allocated memory. The allocated memory is aligned on a page boundary. valloc() returns a NULL pointer if there is an error.
The realloc() function tries to change the size of the allocation pointed to by ptr to size, and return ptr. If there is not enough room to enlarge the memory allocation pointed to by ptr, realloc() creates a new allocation, copies as much of the old data pointed to by ptr as will fit to the new allocation, frees the old allocation, and returns a pointer to the allocated memory. realloc() returns a NULL pointer if there is an error, and the allocation pointed to by ptr is still valid.
The free() function deallocates the memory allocation pointed to by ptr.
The malloc_size() function returns the size of the memory block that backs the allocation pointed to by ptr. The memory block size is always at least as large as the allocation it backs, and may be larger.
The malloc_good_size() function rounds size up to a value that the allocator implementation can allocate without adding any padding and returns that rounded up value.
Return ValuesIf successful, the malloc(), calloc(), and valloc() functions return a pointer to allocated memory. If there is an error, they return a NULL pointer and set errno to ENOMEM.
If successful, the realloc() function returns a pointer to allocated memory. If there is an error, it returns a NULL pointer and sets errno to ENOMEM.
The free() function does not return a value.
Debugging Allocation ErrorsA number of facilities are provided to aid in debugging allocation errors in applications. These facilities are primarily controlled via environment variables. The recognized environment variables and their meanings are documented below.
EnvironmentThe following environment variables change the behavior of the allocation-related functions.
MallocStackLoggingNoCompact If set, record all stacks in a manner that is compatible with the malloc_history program.
Diagnostic MessagesSee Also
leaks(1)
, malloc_history(1)
, abort(3)
|