fs/sys/fsMemMgr.h File Reference


Detailed Description

Memory manager / enabler.

fsMemMgr is a simple memory manager that is able to address some common memory allocation problems like memory leak detection and some wrong pointer handling issues. Detailed information about memory leaks is dumped into a log file.

The memory manager can be easily integrated into a project. It consists of only 3 files: fsMemMgr.h, fsMemMgr_Not.h and fsMemMgr.cpp. The first one enables the memory manager and should be included as soon as possible (typically in a configuration header). Then all (de)allocations through the 'new' and 'delete' operators are redirected into the memory manager so that memory (de)allocations can be tracked from now.

Since the memory manager uses macros to wrap up the 'new' and 'delete' operators it is necessary to guard some code where the operators occur in another meaning than the memory (de)allocation is. For more information see fsMemMgr_Not.h

Configuration

Implementation notes:
Since the memory manager has to store the tracking information in some kind of container and it would be nice to use a standard one (std::map) to keep things simple. It is necessary to provide a custom STL memory allocator in order to prevent recursion during internal (de)allocations. Hence the allocator uses malloc and free to remove itself from the tracking. (Note that there are two versions of the allocator: the standard one and an old SGI's one, it enables the memory manager to be used on my WinCE / PocketPC 2002 platform as well).

Definition in file fsMemMgr.h.

#include "fsMemMgr_NoT.h"
#include "fsMemMgr.h"

Include dependency graph for fsMemMgr.h:

Go to the source code of this file.

Namespaces

namespace  fs
namespace  fs::sys
namespace  fs::sys::mmgr
namespace  fs::sys::mmgr::aux

Defines

#define __FUNCTION__   "???"
#define FS_MMGR_OWN_OPERATORS
 Defined if the internal (de)allocation operators are provided.
#define new
#define delete

Functions

void fs::sys::mmgr::SetModNm (const char *pszModNm)
 Sets a name of the current static module (useful e.g. for multiple DLLs).
void fs::sys::mmgr::aux::Track (const char *pszFunc, const char *pszFile, int nLine)
 Sets a code pos. for the last memory operation (for internal use only).
void * operator new (size_t uSize)
 A monitored version of the 'new' operator.
void operator delete (void *pAddr)
 A monitored version of the 'delete' operator.
void * operator new[] (size_t uSize)
 A monitored version version of the 'new []' operator.
void operator delete[] (void *pAddr)
 A monitored version of the 'delete []' operator.


Define Documentation

#define __FUNCTION__   "???"

Definition at line 59 of file fsMemMgr.h.

#define delete

Value:

(fs::sys::mmgr::aux::Track(__FUNCTION__, __FILE__,           \
 __LINE__), false) ? fs::sys::mmgr::aux::Track("", "", 0) : delete
The macro wraps the 'delete' operator so that the memory tracking code will be executed in parallel. Note that the syntax of a 'delete' statement is not affected (in the case of memory deallocation). The macro expands to: (Track(...), false) ? Track(.0.) : delete ptr;
Note:
The comma operator is involved to hide the tracking code. The second 'Track' is never called, it stands for 'void'.

Definition at line 93 of file fsMemMgr.h.

#define FS_MMGR_OWN_OPERATORS

Defined if the internal (de)allocation operators are provided.

Definition at line 66 of file fsMemMgr.h.

#define new

Value:

(fs::sys::mmgr::aux::Track(__FUNCTION__, __FILE__,              \
 __LINE__), false) ? 0 : new
The macro wraps the 'new' operator so that the memory tracking code will be executed in parallel. Note that the syntax of a 'new' statement is not affected (in the case of memory allocation). The macro expands to: ptr = (Track(...), false) ? 0 : new T;
Note:
The comma operator is involved to hide the tracking code.

Definition at line 83 of file fsMemMgr.h.


Function Documentation

void operator delete ( void *  pAddr  ) 

A monitored version of the 'delete' operator.

void operator delete[] ( void *  pAddr  ) 

A monitored version of the 'delete []' operator.

void* operator new ( size_t  uSize  ) 

A monitored version of the 'new' operator.

void* operator new[] ( size_t  uSize  ) 

A monitored version version of the 'new []' operator.


FipS' Code (Thu Feb 15 22:43:44 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]