| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

mem_realloc_

#include "sflmem.h"
void *
mem_realloc_ (
    void       *client_ptr,             /*  Block of memory to reallocate    */
    size_t      size,                   /*  Desired size of memory block     */
    const char *filename,               /*  Name of source file making call  */
    size_t      lineno                  /*  Line number in calling source    */
)

Synopsis

Reallocates a memory block, which remains part of the same transaction. Use the mem_realloc() macro to call this function! Accepts a pointer to a memory block and the desired size of the new memory block. Returns the address of the new memory block, or NULL if there was not enough memory available. If the specified block was not correctly allocated, dumps the memory allocation list and exits. The desired size must be greater than zero.

Source Code - (sflmem.c)

{
    MEMHDR
        *ptr,
        *next;

    ASSERT (client_ptr);
    ASSERT (size > 0);

    /*  Check that block is valid                                            */
    ptr = CLIENT_2_HDR (client_ptr);
    if (ptr-> tag != MEMTAG)
        mem_tag_err (ptr, filename, lineno);

    /*  Invalidate header                                                    */
    ptr-> tag = MEMUNTAG;

    mem_total -= ptr-> size;
    mem_free_count += 1;

    next = ptr-> next;                  /*  Save where we were linked        */
    list unlink (ptr);                  /*     and unlink                    */

    /*  Reallocate memory block                                              */
    ptr = (MEMHDR *) realloc (ptr, RESERVE_SIZE + size);
    if (ptr == NULL)                    /*  If nothing free, do a hunt       */
      {                                 /*    and try again...               */
        mem_scavenge ();
        ptr = (MEMHDR *) realloc (ptr, RESERVE_SIZE + size);
        if (ptr == NULL)
            return (NULL);              /*  Really in trouble now!           */
      }

#   if (defined (MEM_TRACE))
    trace ("%s (%ld): realloc %d bytes ->%p",
            filename? filename: "-", (long) lineno, size, ptr);
#   endif

    /*  Update header                                                        */
    ptr-> tag  = MEMTAG;
    ptr-> size = size;
    ptr-> file = filename;
    ptr-> line = lineno;

    list_reset (ptr);                   /*  Set up block as list             */
    list_relink_before (ptr, next);     /*  And link where old block was     */

    mem_total += size;                  /*  Keep count of space used         */
    mem_alloc_count += 1;               /*    and number of allocations      */

    return (HDR_2_CLIENT (ptr));
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation