Your Browser is not longer supported
Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...
{{viewport.spaceProperty.prod}}
malloc - memory allocator
&pagelevel(4)&pagelevel
Syntax | #include <stdlib.h> void *malloc(size_t size); |
Description | malloc() allocates contiguous memory of size bytes at execution time.
If size = 0, malloc() returns a null pointer. malloc() is part of a C-specific memory management package that internally administers memory areas which are requested and subsequently freed. As far as possible, all new requests are first satisfied from the areas that are already being managed and only then from the operating system.
|
Return val. | Pointer | to the new memory area if size was not 0 and malloc() was able to allocate new memory. This pointer may be used for any data type. |
Null pointer | if malloc() was unable to provide the memory, e.g. because the available memory space was insufficient for the request or because an error occurred.
errno is set to indicate the error. |
Errors | malloc() will fail if:
ENOMEM The available memory space is insufficient.
|
Notes | The new data area begins on a double-word boundary. The actual length of the data area is equal to the requested length size + 8 bytes for internal administration data. If required, this amount is rounded up to the next power of 2. The sizeof operator should be used to ensure that sufficient space for a variable is requested. If the length of the allocated memory area is exceeded when writing, critical errors may occur in the working memory. malloc() is interrupt-protected as of this version, i.e. the function can now also be used in signal handling and contingency routines.
|
See also | calloc() , free() , realloc() , stdlib.h .
|