D:/WorkDir/SugoiProjects/SugoiTools/include/SugoiTools/memory_manager.h

00001 //==========================================================
00002 // MemoryManager.h
00003 //
00004 // Définition de la classe CMemoryManager
00005 //
00006 //==========================================================
00007 
00008 #ifndef MEMORYMANAGER_H
00009 #define MEMORYMANAGER_H
00010 
00011 //==========================================================
00012 // En-têtes
00013 //==========================================================
00014 #include  "SugoiTools\config.h"
00015 
00016 #if SG_TLS_MEMORY_MANAGER
00017 //#include <Config/Export.h>
00018 #include <Utilities/File.h>
00019 #include <fstream>
00020 #include <map>
00021 #include <stack>
00022 
00023 namespace SGE{
00024     //==========================================================
00025     // Gestionnaire de mémoire - détecte les fuites
00026     //==========================================================
00027     class _SG_TLS_EXPORT CMemoryManager
00028     {
00029     public :
00030 
00031         //----------------------------------------------------------
00032         // Renvoie l'instance de la classe
00033         //----------------------------------------------------------
00034         static CMemoryManager& Instance();
00035 
00036         //----------------------------------------------------------
00037         // Ajoute une allocation mémoire
00038         //----------------------------------------------------------
00039         void* Allocate(std::size_t Size, const CFile& File, int Line, bool Array);
00040 
00041         //----------------------------------------------------------
00042         // Retire une allocation mémoire
00043         //----------------------------------------------------------
00044         void Free(void* Ptr, bool Array);
00045 
00046         //----------------------------------------------------------
00047         // Sauvegarde les infos sur la désallocation courante
00048         //----------------------------------------------------------
00049         void NextDelete(const CFile& File, int Line);
00050 
00051     private :
00052 
00053         //----------------------------------------------------------
00054         // Constructeur par défaut
00055         //----------------------------------------------------------
00056         CMemoryManager();
00057 
00058         //----------------------------------------------------------
00059         // Destructeur
00060         //----------------------------------------------------------
00061         ~CMemoryManager();
00062 
00063         //----------------------------------------------------------
00064         // Inscrit le rapport sur les fuites de mémoire
00065         //----------------------------------------------------------
00066         void ReportLeaks();
00067 
00068         //----------------------------------------------------------
00069         // Types
00070         //----------------------------------------------------------
00071         struct TBlock
00072         {
00073             std::size_t Size;  // Taille allouée
00074             CFile       File;  // Fichier contenant l'allocation
00075             int         Line;  // Ligne de l'allocation
00076             bool        Array; // Est-ce un objet ou un tableau ?
00077         };
00078         typedef std::map<void*, TBlock> TBlockMap;
00079 
00080         //----------------------------------------------------------
00081         // Données membres
00082         //----------------------------------------------------------
00083         std::ofstream      m_File;        // Fichier de sortie
00084         TBlockMap          m_Blocks;      // Blocs de mémoire alloués
00085         std::stack<TBlock> m_DeleteStack; // Pile dont le sommet contient la ligne et le fichier de la prochaine désallocation
00086     };
00087 };//namespace SGE
00088 #endif //SG_TLS_MEMORY_MANAGER
00089 
00090 #endif // MEMORYMANAGER_H

Generated on Mon Mar 19 23:15:11 2007 for SugoiTools by  doxygen 1.4.6-NO