From c30f52090012f4632f4cfe6536abc4af7edfe363 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 20 Apr 2007 23:49:18 +0000 Subject: Decreased memory usage considerably --- debug.cc | 76 ++++++++++++++++------------------------------------------------ 1 file changed, 19 insertions(+), 57 deletions(-) (limited to 'debug.cc') diff --git a/debug.cc b/debug.cc index 4784713f..9e092c4e 100644 --- a/debug.cc +++ b/debug.cc @@ -8,88 +8,43 @@ #include // for the `write' method -int offset = 0; - -std::map ptrs; - -#define PRINT_INC(x) { \ - char buf[128]; \ - std::sprintf(buf, "%d: %p: %s", ++offset, ptr, x); \ - write(1, buf, std::strlen(buf)); \ -} - -#define PRINT_DEC(x) { \ - char buf[128]; \ - std::sprintf(buf, "%d: %p: %s", --offset, ptr, x); \ - write(1, buf, std::strlen(buf)); \ -} +int new_calls = 0; +int new_size = 0; void * operator new(std::size_t size) throw (std::bad_alloc) { void * ptr = std::malloc(size); -#if 0 // jww (2007-04-19): these don't work with boost::regex - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new(std::size_t size) throw (std::bad_alloc)\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void * operator new[](std::size_t size) throw (std::bad_alloc) { void * ptr = std::malloc(size); -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new[](std::size_t) throw (std::bad_alloc)\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void * operator new(std::size_t size, const std::nothrow_t&) throw() { void * ptr = std::malloc(size); -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new(std::size_t size, const std::nothrow_t&) throw()\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void * operator new[](std::size_t size, const std::nothrow_t&) throw() { void * ptr = std::malloc(size); -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new[](std::size_t size, const std::nothrow_t&) throw()\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void operator delete(void * ptr) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete(void * ptr) throw()\n"); - } -#endif std::free(ptr); } void operator delete[](void * ptr) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete[](void * ptr) throw()\n"); - } -#endif std::free(ptr); } void operator delete(void * ptr, const std::nothrow_t&) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete(void * ptr, const std::nothrow_t&) throw()\n"); - } -#endif std::free(ptr); } void operator delete[](void * ptr, const std::nothrow_t&) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete[](void * ptr, const std::nothrow_t&) throw()\n"); - } -#endif std::free(ptr); } @@ -97,13 +52,20 @@ std::ostream * _debug_stream = &std::cerr; bool _free_debug_stream = false; boost::regex _debug_regex; bool _set_debug_regex = false; +bool _debug_regex_on = false; bool _debug_active(const char * const cls) { if (! _set_debug_regex) { - _debug_regex = std::getenv("DEBUG_CLASS"); + const char * user_class = std::getenv("DEBUG_CLASS"); + if (user_class) { + _debug_regex = user_class; + _debug_regex_on = true; + } _set_debug_regex = true; } - return boost::regex_match(cls, _debug_regex); + if (_debug_regex_on) + return boost::regex_match(cls, _debug_regex); + return false; } static struct init_streams { -- cgit v1.2.3