btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / libs / agg / dbg_new / agg_dbg_new.h
blob687358d851f9120741b4a5b4b008dfa6dfd60eed
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 //----------------------------------------------------------------------------
16 // Debuging stuff for catching memory leaks and corruptions
18 //----------------------------------------------------------------------------
19 #ifndef AGG_DBG_NEW_INCLUDED
20 #define AGG_DBG_NEW_INCLUDED
22 #ifdef _WIN32
23 #include <stdio.h>
24 #include <stdarg.h>
25 #endif
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();
36 namespace agg
38 #ifdef _WIN32
39 inline void printf(char* fmt, ...)
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);
50 #endif
52 enum { max_dbg_new_level = 32 };
54 #ifdef AGG_DBG_NEW_CHECK_ADDR
55 enum { max_allocations = 4096 };
56 #endif
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
65 public:
66 watchdoggy(const char* file=0, int line=0, bool report_all=false);
67 ~watchdoggy();
71 #define AGG_WATCHDOGGY(name, report_all) \
72 agg::watchdoggy name(__FILE__, __LINE__, report_all);
73 #endif
75 #ifdef new
76 #undef new
77 #endif
78 #define new AGG_DBG_NEW_OPERATOR