<malloc.h>¶
Userspace heap allocator.
#include <malloc.h>
Functions¶
malloc¶
void * malloc(size_t size);
Allocates a block of memory of the specified size.
| Parameter | Direction | Description |
|---|---|---|
size |
in | The size of the memory block to allocate, in bytes. |
Returns: Pointer to the allocated memory block, or NULL if the allocation fails.
calloc¶
void * calloc(size_t count, size_t size);
Allocates a block of memory for an array of elements, initializes all bytes to zero.
| Parameter | Direction | Description |
|---|---|---|
count |
in | The number of elements to allocate. |
size |
in | The size of each element, in bytes. |
Returns: Pointer to the allocated memory block, or NULL if the allocation fails.
realloc¶
void * realloc(void *ptr, size_t size);
Changes the size of the memory block pointed to by ptr to size bytes.
The contents are kept up to the smaller of the old and new sizes.
| Parameter | Direction | Description |
|---|---|---|
ptr |
in | Pointer to the memory block to resize. If NULL, behaves like malloc. |
size |
in | The new size of the memory block, in bytes. |
Returns: Pointer to the reallocated memory block, or NULL if the reallocation fails; ptr is then left unchanged.
free¶
void free(void *ptr);
Frees a block from malloc(), calloc() or realloc().
| Parameter | Direction | Description |
|---|---|---|
ptr |
in | The block, or NULL to do nothing. |