brealloc basic EMF

Synopsis

Reallocate a block of memory.

Prototype

 #include "uemf.h"

 void *brealloc(B_ARGS_DEC, void* mp, int newsize);

Parameters

B_ARGS_DECCallers source file name and line number. Really two arguments.
mpPointer to a previously allocated memory block using balloc.
newsizeNew size in bytes.

Description

The GoAhead equivalent of realloc.

Note: Allows NULL pointers. Will just do a balloc on the size if that is the case.

Return Value

Return pointer to newly allocated block. If the realloc fails, NULL is returned and the previous buffer is preserved.

Example

/***********************************************************************/
/*
 *    Add a character to a string buffer
 */

static void put_char(strbuf_t *buf, char_t c)
{
    if (buf->count >= buf->size) {
        if (! (buf->flags & STR_REALLOC)) {
            return;
        }
        buf->size += STR_INC;
        if (buf->size > buf->max && buf->size > STR_INC) {
            a_assert(buf->size <= buf->max);
            buf->size -= STR_INC;
            return;
        }
        if (buf->s == NULL) {
            buf->s = balloc(B_L, buf->size * sizeof(char_t));
        } else {
            buf->s = brealloc(B_L, buf->s, buf->size * sizeof(char_t));
        }
    }
    buf->s[buf->count] = c;
    ++buf->count;
}

Stability Classification

Stable.

See Also

balloc, bfree