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 Copyright (C) 2003, 2004 Bayreuth University 00013 2005 Bamberg University 00014 This program is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License as published by 00016 the Free Software Foundation; either version 2 of the License, or 00017 (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00027 00028 */ 00029 #include "libMRML/include/CMutex.h" 00030 typedef long CDebuggingMemoryManagerSize; 00031 00032 // we will allocate a chunk of 10 megs 00033 #define MEMSIZE 20000000 00034 00041 struct lTChunk{ 00042 public: 00044 lTChunk* mPrev; 00045 00047 lTChunk* mNext; 00048 00050 lTChunk* mPreceding; 00051 00053 lTChunk* mFollowing; 00054 00059 CDebuggingMemoryManagerSize mSize; 00060 00067 long mMagic; 00068 }; 00069 00075 class CDebuggingMemoryManager{ 00076 protected: 00077 00080 void FreeChunk(lTChunk* inChunk); 00081 00083 lTChunk* mFreeList; 00085 lTChunk* mUsedList; 00086 00088 lTChunk* mBuffer; 00089 00091 const long cMagic; 00093 const long cUnMagic; 00094 00096 long cVM; 00098 CMutex mMutex; 00099 public: 00100 00104 CDebuggingMemoryManager(const CDebuggingMemoryManagerSize inSize); 00105 00107 void* getMem(CDebuggingMemoryManagerSize inSize); 00108 00110 bool freeMem(void*); 00111 00113 bool isValid()const; 00114 00116 friend ostream& operator <<(ostream& outStream, 00117 const CDebuggingMemoryManager& inMem); 00118 }; 00119 00121 ostream& operator<<(ostream& o, const CDebuggingMemoryManager& inMem); 00122 00124 extern CDebuggingMemoryManager gMemManager; 00125 00126 #endif