drealloc — dmalloc API manualp page

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

drealloc                  dmalloc API functions manual                  drealloc

NAME         top

        drealloc - reallocates memory.

SYNOPSIS         top


        #include "dmalloc.h"

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

DESCRIPTION         top

        The function drealloc() reallocates the memory pointed to by p from src
        to a new block of size size in dest. Both src and dest can either be
        NULL for the memory being reallocated, respectively, from or on the
        heap.
        
        The contents of the memory will be unchanged in the range from the start
        of the region up to the minimum of the old and new sizes.  If the new
        size is larger than the old size, the added memory will not be 
        initialized.

        If p is NULL, then the call is equivalent to dmalloc(size, dest), for
        all values of size and dest.

        If size is 0, and p is not NULL, then the call is equivalent to
        dfree(p, src), for all values of src.

        When non-NULL, src and dest must be initialized by darenainit() before
        being passed to drealloc(). Not doing so results in undefined behaviour.

RETURN VALUE         top

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

ERRORS         top

        ENOMEM  Out of memory. drealloc() 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.
                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     │
        ├────────────────────────────────────┼───────────────┼───────────┤
        │ drealloc()                         │ Thread safety │ MT-Safe   │
        └────────────────────────────────────┴───────────────┴───────────┘

STANDARDS         top

        When dealing with the heap, drealloc() follows the 
        ISO/IEC 9899:2024 §7.24.3.7 C standard for realloc().
dmalloc API functions manual       2026-04-13                           drealloc