Memory Functions

Memory allocation functions.

These functions are utility functions for memory allocation. xmalloc, xrealloc, and xfree are error checking versions of the standard library routines malloc, realloc, and free, respectively. They are guaranteed to never return unless there was no problem. Hence, the caller does not need to check for a NULL return value, and the code that calls these functions is simpler due to the lack of error checks.

function xcalloc
Reserve and initialize storage.

Reserves storage space for an array of num elements, each of length size bytes. Then gives all the bits of each element an initial value of 0.

The storage space to which the return value points is suitably aligned for storage of any type of object. The return value is NULL if there is not enough storage, or if num or size is 0.

public void * xcalloc (	size_t num,       	                size_t size )
 * Source: pm_memory.h:75
 * Author: Dmitry A.Steklenev
 * Version: 1.0
 * Code:

function xfree
Frees a block of storage.

public void xfree ( void * p )
 * Source: pm_memory.h:84
 * Author: Dmitry A.Steklenev
 * Version: 1.0
 * Code:

function xmalloc
Reserves a block of storage of size bytes.

Returns a pointer to the reserved space. The storage space to which the return value points is suitably aligned for storage of any type of object. The return value is NULL if size was specified as zero.

public void * xmalloc (	size_t size )
 * Source: pm_memory.h:42
 * Author: Dmitry A.Steklenev
 * Version: 1.0
 * Code:

function xrealloc
Changes the size of a previously reserved storage block.

Returns a pointer to the reallocated storage block. The storage location of the block may be moved by the realloc function. Thus, the p argument to xrealloc is not necessarily the same as the return value.

If size is 0, xrealloc returns NULL.

The storage to which the return value points is aligned for storage of any type of object.

public void * xrealloc ( void * p,       	                 size_t size )
 * Source: pm_memory.h:59
 * Author: Dmitry A.Steklenev
 * Version: 1.0
 * Code:

function xstrdup
Reserves storage space for a copy of string.

Returns a pointer to the storage space containing the copied string.

public char * xstrdup (	const char * string )
 * Source: pm_memory.h:95
 * Author: Dmitry A.Steklenev
 * Version: 1.0
 * Code: