MIDAS
Loading...
Searching...
No Matches
mleak.h File Reference
#include <map>
#include <sstream>
Include dependency graph for mleak.h:

Go to the source code of this file.

Macros

#define new   new(__FILE__,__LINE__)
 

Functions

voidoperator new (std::size_t size, const char *file, int line)
 
voidoperator new[] (size_t size, const char *file, int line)
 
void operator delete (void *pfs) noexcept
 
void operator delete[] (void *pfs) noexcept
 
void mleak_reset ()
 
void mleak_print ()
 
void mleak_log (bool flag)
 

Variables

static bool _mleak_log {}
 
std::map< void *, std::string > _mleak_list
 

Macro Definition Documentation

◆ new

#define new   new(__FILE__,__LINE__)

Definition at line 90 of file mleak.h.

Function Documentation

◆ mleak_log()

void mleak_log ( bool  flag)

Definition at line 85 of file mleak.h.

85 {
87}
static bool _mleak_log
Definition mleak.h:28
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ mleak_print()

void mleak_print ( )

Definition at line 73 of file mleak.h.

73 {
74 if (_mleak_list.size() == 0)
75 std::cout << "Leak list is empty." << std::endl;
76 else
77 std::cout << "Leak list:" << std::endl;
78
79 // print contents of list
80 for (auto &e : _mleak_list) {
81 std::cout << e.second << std::endl;
82 }
83}
std::map< void *, std::string > _mleak_list
Definition mleak.h:29
static double e(void)
Definition tinyexpr.c:136
Here is the call graph for this function:

◆ mleak_reset()

void mleak_reset ( )

Definition at line 69 of file mleak.h.

69 {
70 _mleak_list.clear();
71}

◆ operator delete()

void operator delete ( void pfs)
noexcept

Definition at line 53 of file mleak.h.

53 {
54 if (_mleak_log)
55 std::cout << "Deleted " << std::hex << pfs << std::dec << std::endl;
56
57 // erase previous allocation from list
58 if (_mleak_list.find(pfs) != _mleak_list.end())
59 _mleak_list.erase(pfs);
60
61 free(pfs); // free pointer
62 return;
63}
Here is the call graph for this function:

◆ operator delete[]()

void operator delete[] ( void pfs)
noexcept

Definition at line 65 of file mleak.h.

65 {
66 operator delete(pfs);
67}
Here is the call graph for this function:

◆ operator new()

void * operator new ( std::size_t  size,
const char file,
int  line 
)

Definition at line 33 of file mleak.h.

33 {
34 void *pfs = malloc(size);
35 if (pfs == nullptr) {
36 std::cerr << "No heap to allocate" << std::endl;
37 exit(-1);
38 }
39 std::stringstream s;
40 s << std::hex << pfs << std::dec << " at " << file << ":" << line << " size " << size;
41 _mleak_list[pfs] = s.str();
42
43 if (_mleak_log)
44 std::cout << "Allocated " << s.str() << std::endl;
45
46 return pfs;
47}
Here is the call graph for this function:

◆ operator new[]()

void * operator new[] ( size_t  size,
const char file,
int  line 
)

Definition at line 49 of file mleak.h.

49 {
50 return operator new(size, file, line);
51}

Variable Documentation

◆ _mleak_list

std::map<void *,std::string> _mleak_list

Definition at line 29 of file mleak.h.

◆ _mleak_log

bool _mleak_log {}
static

Definition at line 28 of file mleak.h.

28{};