/***************************************************************************
* God Wars Mud copyright (C) 1994, 1995, 1996 by Richard Woolcock *
* *
* Legend of Chrystancia copyright (C) 1999, 2000, 2001 by Matthew Little *
* This mud is NOT to be copied in whole or in part, or to be run without *
* the permission of Matthew Little. Nobody else has permission to *
* authorise the use of this code. *
***************************************************************************/
/*
* Matthew Chaplain's Memory Leak Tracer
* Copyright (c) 2000, All Rights Reserved
*/
#include <stdio.h>
#ifndef MC_MEMORY_H_
#define MC_MEMORY_H_
/*
* Initialise the memory using the macro MEMORY_INIT.
*
* To use:
* Copy mc_mem.c and mc_mem.h into your directory.
* In any file that uses malloc or free, include mc_mem.h.
* Instead of using "malloc" and "free", use "MALLOC" and "FREE".
* Ensure that mc_mem.o (compiled from mc_mem.c) is linked in with
* your executable.
*
* The memory leak tracer only traces memory if the symbol DEBUG
* is defined (pass -DDEBUG to the compiler or define it in the code
* for more modular control). If this is not defined, mc_mem.h
* replaces MALLOC and FREE with the normal malloc and free from
* stdlib.h.
*
* Also possible is passing a MEMORY_HASH symbol, with a numeric
* value (preferably a prime number) to set the size of the hash
* to work with. Higher numbers equal more efficiency, at the
* expense of memory.
*
* Lastly, if a symbol MC_MEM_INTRO is passed (using -DMC_MEM_INTRO
* at the compile line), the a short message will be printed
* with the currently set options.
*
* Unless a symbol NOREPORTATEXIT is passed, the tracer will register
* a call to mc_memory_done() with the "atexit" standard function.
*
* All error reporting is done to the standard error file.
*/
#ifndef DEBUG
#define MEMORY_INIT()
#define MALLOC( x ) malloc( (x) )
#define CALLOC( x, y ) calloc( (x), (y) )
#define REALLOC( x, y ) realloc( (x), (y) )
#define FREE( x ) free( (x) )
#else
#define MEMORY_INIT() mc_memory_init()
#define MALLOC( x ) mc_memory_malloc( (x), __FILE__, __LINE__ )
#define CALLOC( x, y ) mc_memory_calloc( (x), (y), __FILE__, __LINE__ )
#define REALLOC( x, y ) mc_memory_realloc( (x), (y), __FILE__, __LINE__ )
#define FREE( x ) mc_memory_free( (x), __FILE__, __LINE__ )
#endif
void mc_memory_init( void );
void *mc_memory_malloc( size_t nSize, const char *szFileName, int nLineNumber );
void *mc_memory_calloc( size_t nElements, size_t nSize,
const char *szFileName, int nLineNumber );
void *mc_memory_realloc( void *pvMemory, size_t nSize,
const char *szFileName, int nLineNumber );
void mc_memory_free( void *pvMemory, const char *szFileName, int nLineNumber );
void mc_memory_done( void );
#endif