[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.8 Memory Allocation Macros


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

MEMERR

 
MEMERR(object_name, size_t n_elements, size_t element_size)

This macro uses wfdb_error to send a short error message of the form WFDB: can't allocate (n_elements*element_size) bytes for object_name). Unless wfdbmemerr(1) has been invoked previously, the process that invoked MEMERR exits immediately.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

SFREE

 
SFREE(object *pointer)

This macro releases memory previously allocated to the object addressed by the specified pointer, somewhat more safely than by invoking the standard free() function. On completion, pointer is set to NULL.

SFREE does nothing if pointer is initially NULL (unlike free(), which may cause the process to crash). If SFREE receives a non-NULL pointer, it passes that pointer to free(), which may cause a crash if the pointer does not point to an allocated block of memory.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

SUALLOC

 
SUALLOC(object_name, size_t n_elements, size_t element_size)

This macro allocates memory sufficient for n_elements items of element_size bytes each, and sets the pointer given by object_name to point to the allocated memory. If there is not enough available memory, SUALLOC invokes MEMERR (above).

SUALLOC does not check to see if object_name already points to allocated memory, which will lead to memory leaks if so.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

SALLOC

 
SALLOC(object_name, size_t n_elements, size_t element_size)

This macro allocates memory sufficient for n_elements items of element_size bytes each, and sets the pointer given by object_name to point to the allocated memory. If there is not enough available memory, SALLOC invokes MEMERR (above).

If object_name is initially non-NULL, SALLOC frees it using SFREE before allocating the requested memory.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

SREALLOC

 
SREALLOC(object_name, size_t n_elements, size_t element_size)

This macro allocates memory sufficient for n_elements items of element_size bytes each, and sets the pointer given by object_name to point to the allocated memory. If there is not enough available memory, SREALLOC invokes MEMERR (above).

SREALLOC attempts to reuse the memory previously allocated to object_name rather than releasing it and then making a new request.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

SSTRCPY

 
SSTRCPY(char *destination, char *source)

This macro copies the source string (including a trailing null character) into newly-allocated memory, and it sets destination to point to the copy. If destination is not NULL on entry, SSTRCPY uses SFREE to release the previously allocated memory.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

George B. Moody (george@mit.edu)