dreallocarray — dmalloc API manualp page

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

dreallocarray             dmalloc API functions manual             dreallocarray

NAME         top

        dreallocarray - reallocates memory.

SYNOPSIS         top


        #include "dmalloc.h"

        void *dreallocarray(void *p, size_t n, size_t size, darena_t *dest, 
                            darena_t *src);

DESCRIPTION         top

        The function dreallocarray() reallocates the memory pointed to by p from
        src to a block in dest that is big enough for n objects of size size.
        Both src and dest can be NULL for the memory being reallocated,
        respectively, from or on the heap.
        
        It is equivalent to the call drealloc(p, n * size);

        However, unlike that drealloc() call, dreallocarray() fails safely in
        the case where the multiplication would overflow. If such an overflow
        occurs, dreallocarray() returns an error.

RETURN VALUE         top

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

ERRORS         top

        ENOMEM  Out of memory. dreallocarray() may have failed for a handful of
                reasons. Possibly, reallocation to a bigger block was attempled,
                and dest was an arena with not enough available space left, or
                the multiplication of n and size would result in integer
                overflow.
                
                Otherwise, for the case of a reallocation to the heap, 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     │
        ├────────────────────────────────────┼───────────────┼───────────┤
        │ dreallocarray()                    │ Thread safety │ MT-Safe   │
        └────────────────────────────────────┴───────────────┴───────────┘

STANDARDS         top

        None.
dmalloc API functions manual       2026-04-13                      dreallocarray