#include "wx/memory.h"
-#if wxUSE_THREADS && defined(__WXDEBUG__) && !defined(__WXMAC__)
+#if wxUSE_THREADS && defined(__WXDEBUG__)
#define USE_THREADSAFE_MEMORY_ALLOCATION 1
#else
#define USE_THREADSAFE_MEMORY_ALLOCATION 0
MemoryCriticalSection() {
memSectionOk = true;
}
+ ~MemoryCriticalSection() {
+ memSectionOk = false;
+ }
};
class MemoryCriticalSectionLocker
bool m_locked;
};
-MemoryCriticalSection &GetMemLocker()
+static MemoryCriticalSection memLocker;
+
+#endif
+
+void * operator new (size_t size, wxChar * fileName, int lineNum)
+{
+ return wxDebugAlloc(size, fileName, lineNum, false, false);
+}
+
+void * operator new (size_t size)
+{
+ return wxDebugAlloc(size, NULL, 0, false);
+}
+
+void operator delete (void * buf)
{
- static MemoryCriticalSection memLocker;
- return memLocker;
+ wxDebugFree(buf, false);
}
+#if wxUSE_ARRAY_MEMORY_OPERATORS
+void * operator new[] (size_t size)
+{
+ return wxDebugAlloc(size, NULL, 0, false, true);
+}
+
+void * operator new[] (size_t size, wxChar * fileName, int lineNum)
+{
+ return wxDebugAlloc(size, fileName, lineNum, false, true);
+}
+
+void operator delete[] (void * buf)
+{
+ wxDebugFree(buf, true);
+}
#endif
// TODO: store whether this is a vector or not.
void * wxDebugAlloc(size_t size, wxChar * fileName, int lineNum, bool isObject, bool WXUNUSED(isVect) )
{
#if USE_THREADSAFE_MEMORY_ALLOCATION
- MemoryCriticalSectionLocker lock(GetMemLocker());
+ MemoryCriticalSectionLocker lock(memLocker);
#endif
// If not in debugging allocation mode, do the normal thing
void wxDebugFree(void * buf, bool WXUNUSED(isVect) )
{
#if USE_THREADSAFE_MEMORY_ALLOCATION
- MemoryCriticalSectionLocker lock(GetMemLocker());
+ MemoryCriticalSectionLocker lock(memLocker);
#endif
if (!buf)
}
//----------------------------------------------------------------------------
-// Final cleanup after all global objects in all files have been destructed
+// Final cleanup after all global objects in all files have been destroyed
//----------------------------------------------------------------------------
// Don't set it to 0 by dynamic initialization
-// Some compilers will realy do the asignment later
+// Some compilers will really do the assignment later
// All global variables are initialized to 0 at the very beginning, and this is just fine.
int wxDebugContextDumpDelayCounter::sm_count;
}
// Even if there is nothing else, make sure that there is at
-// least one clenup counter object
+// least one cleanup counter object
static wxDebugContextDumpDelayCounter wxDebugContextDumpDelayCounter_One;
#endif // (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT