ALLOC(3ACK)

NAME
Malloc, Salloc, Srealloc, st_alloc, st_free - low level memory allocation routines

SYNOPSIS
#include <alloc.h>

char *Malloc(size)
unsigned int size;

char *Salloc(str, size)
char *str; unsigned int size;

char *Srealloc(str, size)
char *str;
unsigned int size;

char *st_alloc(phead, size, count)
char **phead;
unsigned int size;

st_free(ptr, phead, size)
char *ptr;
char **phead;
unsigned int size;

DESCRIPTION
This set of routines provides a checking memory allocation mechanism.

Malloc returns a pointer to a block of at least size bytes, beginning on a boundary suitable for any data type.

Salloc returns a pointer to a block of at least size bytes, initialized with the null-terminated string str.

Srealloc reallocates the string at str to size bytes.

All these routines use malloc and realloc. Free can be used on pointers returned by these routines.

St_alloc and st_free provide a mechanism for maintaining free lists of structures, whose first field is a pointer called next. This field is used to chain free structures together. St_alloc takes three parameters: phead is a pointer to a field containing the head of the free list, size contains the size of the structures, and count indicates how many new structures must be allocated in case the free list is exhausted. It returns a pointer to a zero-initialized structure. St_free also takes three parameters: ptr is a pointer to the structure to be freed, phead is again a pointer to a field containing the head of the free list, and size again contains the size of the structures. These last two routines are best used in a macro.

FILES
~em/modules/h/alloc.h
~em/modules/lib/liballoc.a

SEE ALSO
malloc(3)

DIAGNOSTICS
Malloc, Salloc, Srealloc, and st_alloc call a routine No_Mem if there is no memory available. This routine is not supposed to return. A default one, that gives an error message and stops execution, is provided.