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.
Contents
Entity | Type | Scope | Short Description |
---|---|---|---|
xcalloc | function | public | Reserve and initialize storage. |
xfree | function | public | Frees a block of storage. |
xmalloc | function | public | Reserves a block of storage of size bytes. |
xrealloc | function | public | Changes the size of a previously reserved storage block. |
xstrdup | function | public | Reserves storage space for a copy of string. |
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.
- Source
- pm_memory.h:75
- Author
- Dmitry A.Steklenev
- Version
- 1.0
- Code
public void * xcalloc ( size_t num , size_t size )
function xfree
Frees a block of storage.
- Source
- pm_memory.h:84
- Author
- Dmitry A.Steklenev
- Version
- 1.0
- Code
public void xfree ( void * p )
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.
- Source
- pm_memory.h:42
- Author
- Dmitry A.Steklenev
- Version
- 1.0
- Code
public void * xmalloc ( size_t size )
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.
- Source
- pm_memory.h:59
- Author
- Dmitry A.Steklenev
- Version
- 1.0
- Code
public void * xrealloc ( void * p , size_t size )
function xstrdup
Reserves storage space for a copy of string.
Returns a pointer to the storage space containing the copied string.
- Source
- pm_memory.h:95
- Author
- Dmitry A.Steklenev
- Version
- 1.0
- Code
public char * xstrdup ( const char * string )