1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.2
3 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // Debuging stuff for catching memory leaks and corruptions
18 //----------------------------------------------------------------------------
19 #ifndef AGG_DBG_NEW_INCLUDED
20 #define AGG_DBG_NEW_INCLUDED
27 //#define AGG_DBG_NEW_CHECK_ADDR
29 void* operator new (unsigned size
, const char* file
, int line
);
30 void* operator new [] (unsigned size
, const char* file
, int line
);
31 #define AGG_DBG_NEW_OPERATOR new(__FILE__, __LINE__)
33 void operator delete(void *ptr
) throw();
34 void operator delete [] (void *ptr
) throw();
39 inline void printf(char* fmt
, ...)
41 FILE* fd
= fopen("stdout.txt", "at");
42 static char msg
[1024];
45 vsprintf(msg
, fmt
, arg
);
52 enum { max_dbg_new_level
= 32 };
54 #ifdef AGG_DBG_NEW_CHECK_ADDR
55 enum { max_allocations
= 4096 };
58 // All you need to watch for memory in heap is to declare an object
59 // of this class in your main() or whatever function you need.
60 // It will report you about all bad things happend to new/delete.
61 // Try not to exceed the maximal nested level of declared watchdoggies
62 // (max_dbg_new_level)
66 watchdoggy(const char* file
=0, int line
=0, bool report_all
=false);
71 #define AGG_WATCHDOGGY(name, report_all) \
72 agg::watchdoggy name(__FILE__, __LINE__, report_all);
78 #define new AGG_DBG_NEW_OPERATOR