1e57e5a53SDarkWyrm //---------------------------------------------------------------------------- 2e57e5a53SDarkWyrm // Anti-Grain Geometry - Version 2.2 3e57e5a53SDarkWyrm // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com) 4e57e5a53SDarkWyrm // 5e57e5a53SDarkWyrm // Permission to copy, use, modify, sell and distribute this software 6e57e5a53SDarkWyrm // is granted provided this copyright notice appears in all copies. 7e57e5a53SDarkWyrm // This software is provided "as is" without express or implied 8e57e5a53SDarkWyrm // warranty, and with no claim as to its suitability for any purpose. 9e57e5a53SDarkWyrm // 10e57e5a53SDarkWyrm //---------------------------------------------------------------------------- 11e57e5a53SDarkWyrm // Contact: mcseem@antigrain.com 12e57e5a53SDarkWyrm // mcseemagg@yahoo.com 13e57e5a53SDarkWyrm // http://www.antigrain.com 14e57e5a53SDarkWyrm //---------------------------------------------------------------------------- 15e57e5a53SDarkWyrm // 16e57e5a53SDarkWyrm // Debuging stuff for catching memory leaks and corruptions 17e57e5a53SDarkWyrm // 18e57e5a53SDarkWyrm //---------------------------------------------------------------------------- 19e57e5a53SDarkWyrm #ifndef AGG_DBG_NEW_INCLUDED 20e57e5a53SDarkWyrm #define AGG_DBG_NEW_INCLUDED 21e57e5a53SDarkWyrm 22e57e5a53SDarkWyrm #ifdef _WIN32 23e57e5a53SDarkWyrm #include <stdio.h> 24e57e5a53SDarkWyrm #include <stdarg.h> 25e57e5a53SDarkWyrm #endif 26e57e5a53SDarkWyrm 27e57e5a53SDarkWyrm //#define AGG_DBG_NEW_CHECK_ADDR 28e57e5a53SDarkWyrm 29*9e19c5aeSX512 void* operator new (size_t size, const char* file, int line); 30*9e19c5aeSX512 void* operator new [] (size_t size, const char* file, int line); 31e57e5a53SDarkWyrm #define AGG_DBG_NEW_OPERATOR new(__FILE__, __LINE__) 32e57e5a53SDarkWyrm 33e57e5a53SDarkWyrm void operator delete(void *ptr) throw(); 34e57e5a53SDarkWyrm void operator delete [] (void *ptr) throw(); 35e57e5a53SDarkWyrm 36e57e5a53SDarkWyrm namespace agg 37e57e5a53SDarkWyrm { 38e57e5a53SDarkWyrm #ifdef _WIN32 printf(char * fmt,...)39e57e5a53SDarkWyrm inline void printf(char* fmt, ...) 40e57e5a53SDarkWyrm { 41e57e5a53SDarkWyrm FILE* fd = fopen("stdout.txt", "at"); 42e57e5a53SDarkWyrm static char msg[1024]; 43e57e5a53SDarkWyrm va_list arg; 44e57e5a53SDarkWyrm va_start(arg, fmt); 45e57e5a53SDarkWyrm vsprintf(msg, fmt, arg); 46e57e5a53SDarkWyrm va_end(arg); 47e57e5a53SDarkWyrm fputs(msg, fd); 48e57e5a53SDarkWyrm fclose(fd); 49e57e5a53SDarkWyrm } 50e57e5a53SDarkWyrm #endif 51e57e5a53SDarkWyrm 52e57e5a53SDarkWyrm enum { max_dbg_new_level = 32 }; 53e57e5a53SDarkWyrm 54e57e5a53SDarkWyrm #ifdef AGG_DBG_NEW_CHECK_ADDR 55e57e5a53SDarkWyrm enum { max_allocations = 4096 }; 56e57e5a53SDarkWyrm #endif 57e57e5a53SDarkWyrm 58e57e5a53SDarkWyrm // All you need to watch for memory in heap is to declare an object 59e57e5a53SDarkWyrm // of this class in your main() or whatever function you need. 60e57e5a53SDarkWyrm // It will report you about all bad things happend to new/delete. 61e57e5a53SDarkWyrm // Try not to exceed the maximal nested level of declared watchdoggies 62e57e5a53SDarkWyrm // (max_dbg_new_level) 63e57e5a53SDarkWyrm class watchdoggy 64e57e5a53SDarkWyrm { 65e57e5a53SDarkWyrm public: 66e57e5a53SDarkWyrm watchdoggy(const char* file=0, int line=0, bool report_all=false); 67e57e5a53SDarkWyrm ~watchdoggy(); 68e57e5a53SDarkWyrm }; 69e57e5a53SDarkWyrm } 70e57e5a53SDarkWyrm 71e57e5a53SDarkWyrm #define AGG_WATCHDOGGY(name, report_all) \ 72e57e5a53SDarkWyrm agg::watchdoggy name(__FILE__, __LINE__, report_all); 73e57e5a53SDarkWyrm #endif 74e57e5a53SDarkWyrm 75e57e5a53SDarkWyrm #ifdef new 76e57e5a53SDarkWyrm #undef new 77e57e5a53SDarkWyrm #endif 78e57e5a53SDarkWyrm #define new AGG_DBG_NEW_OPERATOR 79e57e5a53SDarkWyrm 80