* Update mmanager to version from article part 5.
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 18:15:14 +0000 (20:15 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 18:15:14 +0000 (20:15 +0200)
 * Don't let mmanager include engine.h, to prevent loops.

ABM2/Engine/mmanager.cpp
ABM2/Engine/mmanager.h

index 6ed687af58b108754d77a025137b813ed58b824a..549965bdeee1f819c22e1618874aaff958854970 100755 (executable)
@@ -1,9 +1,13 @@
+#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
@@ -84,7 +88,7 @@ void IMMObject::CollectRemainingObjects(bool bEmitWarnings)
                {\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
@@ -96,11 +100,17 @@ void IMMObject::CollectRemainingObjects(bool bEmitWarnings)
 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
index 28ce787b132700013d7c2102c343613543c97a6f..b8ce0779f09f070b1e02f6776af06fa5fe073d43 100755 (executable)
@@ -1,7 +1,8 @@
 #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
@@ -13,6 +14,8 @@ class IMMObject
                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
@@ -40,17 +43,19 @@ public:
 \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