|
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | STANDARDS |
dcalloc dmalloc API functions manual dcalloc
dcalloc - allocates and initializes memory.
#include "dmalloc.h"
void *dcalloc(size_t n, size_t size, darena_t *arena);
The function dcalloc() allocates memory for n objects of size size in
the arena pointed to by arena and initializes it to 0. If arena is NULL,
the memory is allocated on the heap. If the multiplication of n and size
would result in integer overflow, then dcalloc() returns an error. If
size is 0, then dcalloc() returns a unique pointer value that can later
be successfully passed to dfree(). When non-NULL, arena must be
initialized by darenainit() before being passed to dcalloc(). Not doing
so results in undefined behaviour.
On success, dcalloc() returns a pointer to the allocated memory. On
failure, it returns NULL and sets errno.
ENOMEM Out of memory. dcalloc() may have failed because the
multiplication of n and size would result in integer overflow,
or because an arena allocation in an arena with not enough
available space was attempted. Otherwise, for the case of a heap
allocation, the function failed because the heap was full or
because an error occurred while the heap was being initialized.
For an explanation of the terms used in this section, see attributes(7).
┌────────────────────────────────────┬───────────────┬───────────┐
│ Interface │ Attribute │ Value │
├────────────────────────────────────┼───────────────┼───────────┤
│ dcalloc() │ Thread safety │ MT-Safe │
└────────────────────────────────────┴───────────────┴───────────┘
dcalloc() is supposed to behave like calloc() when dealing with the
heap. For this reason, it follows the POSIX standard on top of the
ISO/IEC 9899:2024 §7.24.3.2 C standard.
dmalloc API functions manual 2026-04-13 dcalloc