dcalloc — dmalloc API manualp page

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | STANDARDS

dcalloc                   dmalloc API functions manual                   dcalloc

NAME         top

        dcalloc - allocates and initializes memory.

SYNOPSIS         top


        #include "dmalloc.h"

        void *dcalloc(size_t n, size_t size, darena_t *arena);

DESCRIPTION         top

        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.

RETURN VALUE         top

        On success, dcalloc() returns a pointer to the allocated memory. On
        failure, it returns NULL and sets errno.

ERRORS         top

        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.

ATTRIBUTES         top

        For an explanation of the terms used in this section, see attributes(7).
        ┌────────────────────────────────────┬───────────────┬───────────┐
        │ InterfaceAttributeValue     │
        ├────────────────────────────────────┼───────────────┼───────────┤
        │ dcalloc()                          │ Thread safety │ MT-Safe   │
        └────────────────────────────────────┴───────────────┴───────────┘

STANDARDS         top

        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