src/tools/tMemManager.cpp File Reference

#include "defs.h"
#include <iostream>
#include <sstream>
#include <stdio.h>
#include "tMemManager.h"
#include "tError.h"
#include "tList.h"

Include dependency graph for tMemManager.cpp:

Go to the source code of this file.

Classes

class  tMockMutex
class  tBottleNeck
struct  tAllocationInfo
class  tMemMan
class  tMemManager
struct  chunkinfo
class  memblock

Defines

#define NEW
#define SAFETYBYTES   0
#define PAD   197
#define MAX_SIZE   109

Functions

static wchar_t * wmemset (wchar_t *wcs, wchar_t wc, size_t n) throw ()
void leak ()
void begin_checkleaks ()
void *_cdecl operator new (size_t size) THROW_BADALLOC
void _cdecl operator delete (void *ptr) THROW_NOTHING
void operator delete (void *ptr, bool keep) THROW_NOTHING
void * operator new (size_t size, const char *classn, const char *file, int l) THROW_BADALLOC
void operator delete (void *ptr, const char *classname, const char *file, int line) THROW_NOTHING
void * operator new[] (size_t size) THROW_BADALLOC
void operator delete[] (void *ptr) THROW_NOTHING
void * operator new[] (size_t size, const char *classn, const char *file, int l) THROW_BADALLOC
void operator delete[] (void *ptr, const char *classname, const char *file, int line) THROW_NOTHING
void * real_calloc (size_t nmemb, size_t size)
void * real_malloc (size_t size)
void real_free (void *ptr)
void * real_realloc (void *ptr, size_t size)
char * real_strdup (char const *ptr)
void * real_mmove (void *ptr, size_t size)
char * real_strmove (char *ptr)
char * tStrDup (char const *s)

Variables

static bool reported = false
static tMockMutex st_mutex
static bool inited = false
static tMemManager memman [MAX_SIZE+1]


Define Documentation

#define MAX_SIZE   109

Definition at line 942 of file tMemManager.cpp.

Referenced by tMemMan::Alloc().

#define NEW

Definition at line 67 of file tMemManager.cpp.

#define PAD   197

Definition at line 160 of file tMemManager.cpp.

Referenced by memblock::Check(), and memblock::memblock().

#define SAFETYBYTES   0

Definition at line 158 of file tMemManager.cpp.

Referenced by memblock::Check(), memblock::chunk(), memblock::create(), memblock::data(), memblock::Dispose(), memblock::memblock(), memblock::safety(), and tMemManager::tMemManager().


Function Documentation

void begin_checkleaks (  ) 

Definition at line 266 of file tMemManager.cpp.

00266                        {
00267 #ifdef LEAKFINDER
00268     checkleaks=true;
00269 #endif
00270 }

void leak (  ) 

Definition at line 134 of file tMemManager.cpp.

References NULL, tMemManBase::Profile(), and reported.

00134            {
00135     if (!reported)
00136     {
00137         reported=true;
00138 #ifdef DEBUG
00139 #ifdef WIN32
00140         MessageBox (NULL, "Memory leak detected!" , "Memory Leak", MB_OK);
00141 #else
00142         std::cerr << "\n\nMemory leak detected!\n\n";
00143 #endif
00144 #endif
00145         tMemManBase::Profile();
00146     }
00147 }

Here is the call graph for this function:

void operator delete ( void *  ptr,
const char *  classname,
const char *  file,
int  line 
)

Definition at line 1327 of file tMemManager.cpp.

01330                                                                                                   {
01331     tAllocationInfo info( false );

void operator delete ( void *  ptr,
bool  keep 
)

Definition at line 1279 of file tMemManager.cpp.

01282                                                         {
01283     tAllocationInfo info( false );
01284 
01285     if (ptr){
01286         if (keep)
01287             tMemMan::DisposeButKeep(info, ptr);
01288         else
01289             tMemMan::Dispose(info, ptr);

void _cdecl operator delete ( void *  ptr  ) 

Definition at line 1272 of file tMemManager.cpp.

01275                                                      {
01276     tAllocationInfo info( false );
01277 

void operator delete[] ( void *  ptr,
const char *  classname,
const char *  file,
int  line 
)

Definition at line 1386 of file tMemManager.cpp.

01389                                                                                                      {
01390     tAllocationInfo info( true );

void operator delete[] ( void *  ptr  ) 

Definition at line 1343 of file tMemManager.cpp.

01346                                                  {
01347     tAllocationInfo info( true );
01348 

void* operator new ( size_t  size,
const char *  classn,
const char *  file,
int  l 
)

Definition at line 1293 of file tMemManager.cpp.

01296                                                                                               {
01297     tAllocationInfo info( false );
01298 #ifdef LEAKFINDER
01299     info.filename=file;
01300     info.classname=classn;
01301     info.line=l;
01302 
01303     info.checksum =
01304 #ifndef PROFILER 
01305         size +
01306 #endif 
01307         info.line * 19671;
01308 
01309     int c=1379;
01310     while (*file){
01311         info.checksum = (info.checksum + (*file)*c) % MAXCHECKSUM;
01312         c             = (c * 79              ) % MAXCHECKSUM;
01313         file++;
01314     }
01315     while (*classn){
01316         info.checksum = (info.checksum + (*classn)*c) % MAXCHECKSUM;
01317         c             = (c * 79                ) % MAXCHECKSUM;
01318         classn++;
01319     }
01320 
01321 #ifdef PROFILER
01322     while (checksum_filename[info.checksum] && (checksum_filename[info.checksum] != info.filename || checksum_line[info.checksum] != info.line))
01323     info.checksum = (info.checksum+1) % MAXCHECKSUM;
01324 #endif
01325 

void* _cdecl operator new ( size_t  size  ) 

Definition at line 1261 of file tMemManager.cpp.

01264                                                             {
01265     tAllocationInfo info( false );
01266 
01267 #ifdef LEAKFINDER
01268 #ifndef HAVE_LIBZTHREAD
01269     info.checksum = size;
01270 #endif

void* operator new[] ( size_t  size,
const char *  classn,
const char *  file,
int  l 
)

Definition at line 1352 of file tMemManager.cpp.

01355                                                                                                {
01356     tAllocationInfo info( true );
01357 #ifdef LEAKFINDER
01358     info.filename=file;
01359     info.classname=classn;
01360     info.line=l;
01361 
01362     info.checksum =
01363 #ifndef PROFILER 
01364     size +
01365 #endif 
01366     info.line * 19671;
01367     
01368     int c=1379;
01369     while (*file){
01370         info.checksum = (info.checksum + (*file)*c) % MAXCHECKSUM;
01371         c             = (c * 79              ) % MAXCHECKSUM;
01372         file++;
01373     }
01374     while (*classn){
01375         info.checksum = (info.checksum + (*classn)*c) % MAXCHECKSUM;
01376         c             = (c * 79                ) % MAXCHECKSUM;
01377         classn++;
01378     }
01379     
01380 #ifdef PROFILER
01381     while (checksum_filename[info.checksum] && (checksum_filename[info.checksum] != info.filename || checksum_line[info.checksum] != info.line))
01382     info.checksum = (info.checksum+1) % MAXCHECKSUM;
01383 #endif
01384 

void* operator new[] ( size_t  size  ) 

Definition at line 1333 of file tMemManager.cpp.

01336                                                     {
01337     tAllocationInfo info( true );
01338 #ifdef LEAKFINDER
01339 #ifndef HAVE_LIBZTHREAD
01340     info.checksum = size % MAXCHECKSUM;
01341 #endif

void* real_calloc ( size_t  nmemb,
size_t  size 
)

Definition at line 1516 of file tMemManager.cpp.

01520 {

void real_free ( void *  ptr  ) 

Definition at line 1526 of file tMemManager.cpp.

01530 {

void* real_malloc ( size_t  size  ) 

Definition at line 1521 of file tMemManager.cpp.

01525 {

void* real_mmove ( void *  ptr,
size_t  size 
)

Definition at line 1541 of file tMemManager.cpp.

01545 {
01546     // create new memory, copy, free old memory
01547     void * ret = tNEW(char)[size];
01548     memcpy( ret, ptr, size );
01549     real_free( ptr );

void* real_realloc ( void *  ptr,
size_t  size 
)

Definition at line 1531 of file tMemManager.cpp.

01535 {

char* real_strdup ( char const *  ptr  ) 

Definition at line 1536 of file tMemManager.cpp.

01540 {

char* real_strmove ( char *  ptr  ) 

Definition at line 1551 of file tMemManager.cpp.

Referenced by tStrDup().

01555 {
01556     if ( ptr )
01557         return static_cast< char * >( real_mmove( ptr, strlen( ptr ) + 1 ) );

Here is the caller graph for this function:

char* tStrDup ( char const *  s  ) 

Definition at line 1561 of file tMemManager.cpp.

References real_strmove(), and strdup.

01565 {

Here is the call graph for this function:

static wchar_t* wmemset ( wchar_t *  wcs,
wchar_t  wc,
size_t  n 
) throw () [inline, static]

Definition at line 122 of file tMemManager.cpp.

Referenced by memblock::Alloc(), and memblock::Dispose().

00123 {
00124     // fill memory
00125     for( size_t i = 0; i < n; ++i )
00126     {
00127         wcs[i] = wc;
00128     }
00129 
00130     return wcs;
00131 }

Here is the caller graph for this function:


Variable Documentation

bool inited = false [static]

Definition at line 246 of file tMemManager.cpp.

Referenced by nConfItemVersionWatcher::OnVersionChange(), and uPlayerPrototype::uPlayerPrototype().

tMemManager memman[MAX_SIZE+1] [static]

Definition at line 945 of file tMemManager.cpp.

bool reported = false [static]

Definition at line 89 of file tMemManager.cpp.

Referenced by leak(), and sn_Listen().

tMockMutex st_mutex [static]

Definition at line 103 of file tMemManager.cpp.


Generated on Sat Mar 15 23:12:06 2008 for Armagetron Advanced by  doxygen 1.5.4