| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2000-2014 Ericsson Telecom AB |
| 3 | // All rights reserved. This program and the accompanying materials |
| 4 | // are made available under the terms of the Eclipse Public License v1.0 |
| 5 | // which accompanies this distribution, and is available at |
| 6 | // http://www.eclipse.org/legal/epl-v10.html |
| 7 | /////////////////////////////////////////////////////////////////////////////// |
| 8 | #ifndef DBGNEW_HH |
| 9 | #define DBGNEW_HH |
| 10 | |
| 11 | #ifndef _Common_memory_H |
| 12 | #include "memory.h" |
| 13 | #endif |
| 14 | |
| 15 | #ifdef MEMORY_DEBUG |
| 16 | |
| 17 | class debug_new_counter_t |
| 18 | { |
| 19 | static int count; |
| 20 | static const char * progname; |
| 21 | public: |
| 22 | debug_new_counter_t(); |
| 23 | ~debug_new_counter_t(); |
| 24 | void set_program_name(const char *pgn); |
| 25 | }; |
| 26 | // implementation in new.cc |
| 27 | |
| 28 | // An instance for every translation unit. Because each instance is constructed |
| 29 | // before main() and probably before any other global object, |
| 30 | // it is destroyed after main() ends and all global objects are destroyed. |
| 31 | // The last destructor runs check_mem_leak(). |
| 32 | static debug_new_counter_t debug_new_counter; |
| 33 | |
| 34 | // Custom placement new for memory tracking |
| 35 | void* operator new(size_t size, const char* file, int line); |
| 36 | void* operator new[](size_t size, const char* file, int line); |
| 37 | |
| 38 | // Redirect "normal" new to memory-tracking placement new. |
| 39 | #define new new(__FILE__, __LINE__) |
| 40 | |
| 41 | #endif // MEMORY_DEBUG |
| 42 | |
| 43 | #endif |