+#ifndef USING_ENGINUITY\r
+#define USING_ENGINUITY\r
+#endif\r
#include "engine.h"\r
\r
\r
IMMObject *IMMObject::liveObjects=0;\r
IMMObject *IMMObject::deadObjects=0;\r
std::list<IMMObject *> IMMObject::heapObjects;\r
+unsigned long IMMObject::heapUsage=0;\r
\r
IMMObject::IMMObject()\r
{\r
{\r
//copy the object to a temporary buffer so that our '10 bytes' message doesn't\r
//cause an access violation\r
- char szBuf[11]; ZeroMemory(szBuf,11);\r
+ char szBuf[11]; memset(szBuf,0,11);\r
memcpy(szBuf,liveObjects,min(liveObjects->size(),10));\r
CLog::Get().Write(LOG_APP,IDS_UNRELEASED_OBJECT,liveObjects,liveObjects->size(),szBuf);\r
}\r
void* IMMObject::operator new(size_t objsize)\r
{\r
void *newObj=malloc(objsize);\r
+ heapUsage+=objsize;\r
heapObjects.push_back((IMMObject*)newObj);\r
+ ((IMMObject*)newObj)->heapAllocSize=objsize;\r
return newObj;\r
}\r
\r
void IMMObject::operator delete(void* obj)\r
{\r
- if(!((IMMObject*)obj)->bIsStackAllocated)free(obj);\r
+ if(!((IMMObject*)obj)->bIsStackAllocated)\r
+ {\r
+ heapUsage-=((IMMObject*)obj)->heapAllocSize;\r
+ free(obj);\r
+ }\r
}\r
#ifndef MMANAGER_H_INCLUDED\r
#define MMANAGER_H_INCLUDED\r
\r
-#include "engine.h"\r
+#include <list>\r
+#include <cassert>\r
\r
class IMMObject\r
{\r
long refCount;\r
bool bIsStackAllocated;\r
static std::list<IMMObject*> heapObjects;\r
+ static unsigned long heapUsage;\r
+ unsigned long heapAllocSize;\r
protected:\r
IMMObject();\r
virtual ~IMMObject();\r
\r
~CMMPointer(){if(obj)obj->Release();}\r
\r
- inline void operator =(const CMMPointer<T> &p)\r
+ inline CMMPointer<T> &operator =(const CMMPointer<T> &p)\r
{\r
if(obj)obj->Release();\r
obj=p.obj;\r
if(obj)obj->AddRef();\r
+ return *this;\r
}\r
- inline void operator =(T* o)\r
+ inline CMMPointer<T> &operator =(T* o)\r
{\r
if(obj)obj->Release();\r
obj=o;\r
if(obj)obj->AddRef();\r
+ return *this;\r
}\r
\r
inline T& operator *() const\r