KeosMemoryManager.h

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
00019  *
00020  */
00021 
00022 //==========================================================
00023 // ORIGINAL COPYRIGHT FOLLOWS
00024 //==========================================================
00025 // Yes::Engine - Free C++ 3D engine
00026 //
00027 // Copyright (C) 2004-2005 Laurent Gomila
00028 //
00029 // This program is free software; you can redistribute it and/or
00030 // modify it under the terms of the GNU General Public License
00031 // as published by the Free Software Foundation; either version 2
00032 // of the License, or (at your option) any later version.
00033 //
00034 // This program is distributed in the hope that it will be useful,
00035 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00036 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00037 // GNU General Public License for more details.
00038 //
00039 // You should have received a copy of the GNU General Public License
00040 // along with this program; if not, write to the Free Software
00041 // Foundation, Inc.,
00042 // 59 Temple Place - Suite 330,
00043 // Boston, MA  02111-1307, USA.
00044 //
00045 // E-mail : laurent.gom@gmail.com
00046 //==========================================================
00047 
00048 #ifndef KEOS_MEMORYMANAGER_H
00049 #define KEOS_MEMORYMANAGER_H
00050 
00051 #include "KeosNoMemoryMacros.h"
00052 
00053 #include "KeosPlatform.h"
00054 #include "KeosStdHeaders.h"
00055 #include "KeosFile.h"
00056 
00057 namespace Keos
00058 {
00059   //-----------------------------------------------------------------------
00063   class KEOS_EXPORT CMemoryManager
00064   {
00065   public :
00066 
00070     static CMemoryManager& Instance();
00071 
00079     void* Allocate(size_t nSize, const CFile& File, int nLine, bool bArray);
00080 
00085     void Free(void* pPtr, bool bArray);
00086 
00091     void NextDelete(const CFile& File, int nLine);
00092 
00096     ~CMemoryManager();
00097 
00098   private :
00099 
00103     CMemoryManager();
00104 
00108     void ReportLeaks();
00109 
00110     // Types
00111     struct TBlock
00112     {
00113       size_t      nSize;      // Allocated size
00114       CFile       File;       // File containing the allocation
00115       int         nLine;      // Line of the allocation
00116       bool        bArray;     // Object or array ?
00117     };
00118     typedef std::map<void*, TBlock> TBlockMap;
00119 
00121     std::ofstream      m_File;
00123     TBlockMap          m_Blocks;
00125     std::stack<TBlock> m_DeleteStack;
00126   };
00127 
00128 } // namespace Keos
00129 
00130 #include "KeosMemoryMacros.h"
00131 
00132 #endif // KEOS_MEMORYMANAGER_H

Generated on Fri Mar 9 14:29:02 2007 for Keos by  doxygen 1.5.1-p1