summaryrefslogtreecommitdiff
path: root/zen/debug_new.h
diff options
context:
space:
mode:
Diffstat (limited to 'zen/debug_new.h')
-rw-r--r--zen/debug_new.h74
1 files changed, 2 insertions, 72 deletions
diff --git a/zen/debug_new.h b/zen/debug_new.h
index 6007344d..4ef0106e 100644
--- a/zen/debug_new.h
+++ b/zen/debug_new.h
@@ -7,10 +7,6 @@
#ifndef DEBUGNEW_H_INCLUDED
#define DEBUGNEW_H_INCLUDED
-#include <string>
-#include <sstream>
-#include <cstdlib> //malloc(), free()
-
#ifndef _MSC_VER
#error currently for use with MSC only
#endif
@@ -21,10 +17,9 @@ Better std::bad_alloc
overwrite "operator new" to automatically write mini dump and get info about bytes requested
1. Compile "debug_new.cpp"
-2. C/C++ -> Advanced: Forced Include File: zen/debug_new.h
Minidumps http://msdn.microsoft.com/en-us/library/windows/desktop/ee416349(v=vs.85).aspx
----------
+----------------------------------------------------------------------------------------
1. Compile "debug_new.cpp"
2. Compile "release" build with:
- C/C++ -> General: Debug Information Format: "Program Database" (/Zi).
@@ -36,74 +31,9 @@ Optional:
- C/C++ -> Optimization: Disabled (/Od)
*/
-namespace mem_check
-{
-class BadAllocDetailed : public std::bad_alloc
+namespace debug_tools
{
-public:
- explicit BadAllocDetailed(size_t allocSize)
- {
- errorMsg = "Memory allocation failed: ";
- errorMsg += numberToString(allocSize);
- }
-
- ~BadAllocDetailed() throw() {}
-
- virtual const char* what() const throw()
- {
- return errorMsg.c_str();
- }
-
-private:
- template <class T>
- static std::string numberToString(const T& number) //convert number to string the C++ way
- {
- std::ostringstream ss;
- ss << number;
- return ss.str();
- }
-
- std::string errorMsg;
-};
-
-#ifdef _MSC_VER
void writeMinidump();
-#endif
-}
-
-inline
-void* operator new(size_t size)
-{
- void* newMem = ::malloc(size);
- if (!newMem)
- {
-#ifdef _MSC_VER
- mem_check::writeMinidump();
-#endif
- throw mem_check::BadAllocDetailed(size);
- }
- return newMem;
-}
-
-
-inline
-void operator delete(void* ptr)
-{
- ::free(ptr);
-}
-
-
-inline
-void* operator new[](size_t size)
-{
- return operator new(size);
-}
-
-
-inline
-void operator delete[](void* ptr)
-{
- operator delete(ptr);
}
#endif // DEBUGNEW_H_INCLUDED
bgstack15