00001 // -*- mode: c++ -*- 00002 #ifndef _CDEBUGMEMORYMANAGER 00003 #define _CDEBUGMEMORYMANAGER 00004 #include "libMRML/include/uses-declarations.h" 00005 #include <iostream> 00006 // -*- mode: c++ -*- 00007 /* 00008 00009 GIFT, a flexible content based image retrieval system. 00010 Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 00026 */ 00027 #include "libMRML/include/CMutex.h" 00028 typedef long CDebuggingMemoryManagerSize; 00029 00030 // we will allocate a chunk of 10 megs 00031 #define MEMSIZE 20000000 00032 00039 struct lTChunk{ 00040 public: 00042 lTChunk* mPrev; 00043 00045 lTChunk* mNext; 00046 00048 lTChunk* mPreceding; 00049 00051 lTChunk* mFollowing; 00052 00057 CDebuggingMemoryManagerSize mSize; 00058 00065 long mMagic; 00066 }; 00067 00073 class CDebuggingMemoryManager{ 00074 protected: 00075 00078 void FreeChunk(lTChunk* inChunk); 00079 00081 lTChunk* mFreeList; 00083 lTChunk* mUsedList; 00084 00086 lTChunk* mBuffer; 00087 00089 const long cMagic; 00091 const long cUnMagic; 00092 00094 long cVM; 00096 CMutex mMutex; 00097 public: 00098 00102 CDebuggingMemoryManager(const CDebuggingMemoryManagerSize inSize); 00103 00105 void* getMem(CDebuggingMemoryManagerSize inSize); 00106 00108 bool freeMem(void*); 00109 00111 bool isValid()const; 00112 00114 friend ostream& operator <<(ostream& outStream, 00115 const CDebuggingMemoryManager& inMem); 00116 }; 00117 00119 ostream& operator<<(ostream& o, const CDebuggingMemoryManager& inMem); 00120 00122 extern CDebuggingMemoryManager gMemManager; 00123 00124 #endif