From: Matthijs Kooijman Date: Mon, 11 Jun 2007 18:15:14 +0000 (+0200) Subject: * Update mmanager to version from article part 5. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=b5abb5111b87fc7973c1e3f3f989e4adc92362d6;p=matthijs%2FABM2.git * Update mmanager to version from article part 5. * Don't let mmanager include engine.h, to prevent loops. --- diff --git a/ABM2/Engine/mmanager.cpp b/ABM2/Engine/mmanager.cpp index 6ed687a..549965b 100755 --- a/ABM2/Engine/mmanager.cpp +++ b/ABM2/Engine/mmanager.cpp @@ -1,9 +1,13 @@ +#ifndef USING_ENGINUITY +#define USING_ENGINUITY +#endif #include "engine.h" IMMObject *IMMObject::liveObjects=0; IMMObject *IMMObject::deadObjects=0; std::list IMMObject::heapObjects; +unsigned long IMMObject::heapUsage=0; IMMObject::IMMObject() { @@ -84,7 +88,7 @@ void IMMObject::CollectRemainingObjects(bool bEmitWarnings) { //copy the object to a temporary buffer so that our '10 bytes' message doesn't //cause an access violation - char szBuf[11]; ZeroMemory(szBuf,11); + char szBuf[11]; memset(szBuf,0,11); memcpy(szBuf,liveObjects,min(liveObjects->size(),10)); CLog::Get().Write(LOG_APP,IDS_UNRELEASED_OBJECT,liveObjects,liveObjects->size(),szBuf); } @@ -96,11 +100,17 @@ void IMMObject::CollectRemainingObjects(bool bEmitWarnings) void* IMMObject::operator new(size_t objsize) { void *newObj=malloc(objsize); + heapUsage+=objsize; heapObjects.push_back((IMMObject*)newObj); + ((IMMObject*)newObj)->heapAllocSize=objsize; return newObj; } void IMMObject::operator delete(void* obj) { - if(!((IMMObject*)obj)->bIsStackAllocated)free(obj); + if(!((IMMObject*)obj)->bIsStackAllocated) + { + heapUsage-=((IMMObject*)obj)->heapAllocSize; + free(obj); + } } diff --git a/ABM2/Engine/mmanager.h b/ABM2/Engine/mmanager.h index 28ce787..b8ce077 100755 --- a/ABM2/Engine/mmanager.h +++ b/ABM2/Engine/mmanager.h @@ -1,7 +1,8 @@ #ifndef MMANAGER_H_INCLUDED #define MMANAGER_H_INCLUDED -#include "engine.h" +#include +#include class IMMObject { @@ -13,6 +14,8 @@ class IMMObject long refCount; bool bIsStackAllocated; static std::list heapObjects; + static unsigned long heapUsage; + unsigned long heapAllocSize; protected: IMMObject(); virtual ~IMMObject(); @@ -40,17 +43,19 @@ public: ~CMMPointer(){if(obj)obj->Release();} - inline void operator =(const CMMPointer &p) + inline CMMPointer &operator =(const CMMPointer &p) { if(obj)obj->Release(); obj=p.obj; if(obj)obj->AddRef(); + return *this; } - inline void operator =(T* o) + inline CMMPointer &operator =(T* o) { if(obj)obj->Release(); obj=o; if(obj)obj->AddRef(); + return *this; } inline T& operator *() const