edbee - Qt Editor Library
debug_allocs.h
Go to the documentation of this file.
1 
6 #pragma once
10 
11 class QMutex;
12 
13 //#if !defined(__APPLE__)
14 //#include <malloc>
15 //#endif
16 #include <cstring> // for size_t
17 #include <map>
18 
19 namespace edbee {
20 
23 {
24  void* pointer;
25  std::size_t size;
26  char* file;
27  int line;
28 // MemoryLeakInfo() : p(0), size(0), file(0), line(0) {}
29 // MemoryLeakInfo( void *p1, std::size_t size1, char *file1, int line1) : p(p1), size(size1), file(file1), line(line1) {}
30  void clear() { pointer=0; size=0; file=0; line=0; }
31 };
32 
35 {
36 public:
37 
39  virtual ~DebugAllocationList();
40 
41  void clear();
42  int size() { return allocationList_.size(); }
43  inline bool isRunning() { return running_; }
44 
45  void pause( bool val )
46  {
47  if( started_ ) {
48  running_ = !val;
49  }
50  }
51 
52 
53  QMutex* mutex();
54 
55 public:
56  void start( bool checkDelete );
57  int stop();
58 
59  DebugAllocation* find(void* p);
60  DebugAllocation* add (void* p, size_t size, char* file, int line);
61  bool del (void* p);
62 
63  bool checkDelete();
64 
65 public:
66 
67  static DebugAllocationList* instance();
68 
69 
70 private:
71  std::map< void *, DebugAllocation*> allocationList_;
72  bool checkDelete_;
73  QMutex* mutex_;
74  bool running_;
75  bool started_;
76 
77 
78  friend void* debug_malloc(size_t size, const char* file, const int line);
79  friend void debug_free (void* p, const char* file, const int line);
80 
81 
82 };
83 
84 
85 } // edbee
void clear()
Definition: debug_allocs.h:30
This structure is used to &#39;remember&#39; what is allocated at which place.
Definition: debug_allocs.h:22
void debug_free(void *p, const char *file, const int line)
frees the given pointer
Definition: debug_new.cpp:54
int size()
Definition: debug_allocs.h:42
int line
Definition: debug_allocs.h:27
This class is used to remember all memory leakds.
Definition: debug_allocs.h:34
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
std::size_t size
Definition: debug_allocs.h:25
void * debug_malloc(size_t size, const char *file, const int line)
Logs a malloc operation.
Definition: debug_new.cpp:25
#define add(key, value)
Definition: factorykeymap.cpp:15
bool isRunning()
Definition: debug_allocs.h:43
void pause(bool val)
Definition: debug_allocs.h:45
void * pointer
Definition: debug_allocs.h:24
char * file
Definition: debug_allocs.h:26