1//---------------------------------------------------------------------------- 2// Anti-Grain Geometry - Version 2.2 3// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com) 4// 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. 9// 10//---------------------------------------------------------------------------- 11// Contact: mcseem@antigrain.com 12// mcseemagg@yahoo.com 13// http://www.antigrain.com 14//---------------------------------------------------------------------------- 15// 16// Debuging stuff for catching memory leaks and corruptions 17// 18//---------------------------------------------------------------------------- 19#ifndef AGG_DBG_NEW_INCLUDED 20#define AGG_DBG_NEW_INCLUDED 21 22#ifdef _WIN32 23#include <stdio.h> 24#include <stdarg.h> 25#endif 26 27//#define AGG_DBG_NEW_CHECK_ADDR 28 29void* operator new (size_t size, const char* file, int line); 30void* operator new [] (size_t size, const char* file, int line); 31#define AGG_DBG_NEW_OPERATOR new(__FILE__, __LINE__) 32 33void operator delete(void *ptr) throw(); 34void operator delete [] (void *ptr) throw(); 35 36namespace agg 37{ 38 #ifdef _WIN32 39 inline void printf(char* fmt, ...) 40 { 41 FILE* fd = fopen("stdout.txt", "at"); 42 static char msg[1024]; 43 va_list arg; 44 va_start(arg, fmt); 45 vsprintf(msg, fmt, arg); 46 va_end(arg); 47 fputs(msg, fd); 48 fclose(fd); 49 } 50 #endif 51 52 enum { max_dbg_new_level = 32 }; 53 54#ifdef AGG_DBG_NEW_CHECK_ADDR 55 enum { max_allocations = 4096 }; 56#endif 57 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) 63 class watchdoggy 64 { 65 public: 66 watchdoggy(const char* file=0, int line=0, bool report_all=false); 67 ~watchdoggy(); 68 }; 69} 70 71#define AGG_WATCHDOGGY(name, report_all) \ 72 agg::watchdoggy name(__FILE__, __LINE__, report_all); 73#endif 74 75#ifdef new 76#undef new 77#endif 78#define new AGG_DBG_NEW_OPERATOR 79 80