Memory

Name

Memory -- Memory allocation and debugging functions.

Functions

#definexmalloc()
#definexrealloc()
#definexstrdup()
voidxdoneinit ()
voidxmemchk ()
voidxmemdmp ()
voidxclaim ()
voidxmemdist ()
voidxfree ()

Includes

#include <memory.h>

Description

This set of functions is semantically similar functions to standard C library memory allocation routines. When memory debugging is enabled these functions include support to detect buffer overruns. When memory debugging is not enabled the allocation and free calls are wrappers around the standard C allocation routines, and checking routines are null ops.

Memory debugging is enabled when DEBUG_MEM is defined at compilation time. On Unix systems, the configure script has a command-line option --enable-debug-mem. On Win32, a memory debugging is enabled in the debug configuration.

Functions

xmalloc()

#define xmalloc(x) _xmalloc(x,__FILE__,__LINE__)

Allocates a block of memory. Semantically equivalent to malloc().

Parameters

x

size of allocation.

 


xrealloc()

#define xrealloc(p,x) _xrealloc(p, x,__FILE__,__LINE__)

Re-sizes a block of memory. Semantically equivalent to realloc().

Parameters

p

Pointer to block to be re-dimensioned.

 

x

New size.

 


xstrdup()

#define xstrdup(str) _xstrdup(str,__FILE__,__LINE__)

xmalloc()'s sufficient memory to store str, copies str into it, and returns pointer to new string. Semantically equivalent to strdup().


xdoneinit ()

void
xdoneinit (void);

Marks end of an applications initialization period. For media applications with real-time data transfer it's sometimes helpful to distinguish between memory allocated during application initialization and when application is running.


xmemchk ()

void
xmemchk (void);

Check for bounds overruns in all memory allocated with xmalloc(), xrealloc(), and xstrdup(). Information on corrupted blocks is rendered on the standard error stream. This includes where the block was allocated, the size of the block, and the number of allocations made since the block was created.


xmemdmp ()

void
xmemdmp (void);

Dumps the address, size, age, and point of allocation in code.


xclaim ()

void
xclaim (void *addr,
        const char *filen,
        int line);

Coerces information in allocation table about allocation file and line to be filen and line . This is used by the evil block_alloc() and should probably not be used anywhere else ever.

Parameters

addr

address

 

filen

new filename

 

line

new allocation line

 


xmemdist ()

void
xmemdist (FILE *fp);

Dumps information on existing memory allocations to file.

Parameters

fp

file pointer

 


xfree ()

void
xfree (void *p);

Free block of memory. Semantically equivalent to free(), but checks for bounds overruns in p and tidies up state associated additional functionality.

Must be used to free memory allocated with xmalloc(), xrealloc(), and xstrdup().

Parameters

p

pointer to block to freed.

 

Types and Values