#include "gestionnaire_memoire.h" #include #include #include #define test(l) MessageBox(NULL,l,"Test",MB_OK); namespace GM { GESTIONNAIRE_MEMOIRE::GESTIONNAIRE_MEMOIRE() : fichier_sortie("Memoire.txt") { test("test2") fichier_sortie << " =========================================" < Gestionnaire de mémoire " << std::endl << " =========================================" <second.taille; fichier_sortie << "-> 0x"<first << " | " << std::setw(7) << std::setfill(' ') << static_cast(i->second.taille) << " octets" << " | " << i->second.fichier.nom_complet() << " (" << i->second.ligne << ")" <first); } fichier_sortie << std::endl << "-----------" << std::endl << "Allocations non désallouées : " << static_cast(allocations.size()) <(taille_fuite) << " octets" << std::endl; } void* GESTIONNAIRE_MEMOIRE::allouer(std::size_t taille, const FICHIER& fichier , int ligne, bool tableau) { void* pointeur = malloc(taille); IALLOC nouvelle_alloc; nouvelle_alloc.taille = taille; nouvelle_alloc.fichier = fichier; nouvelle_alloc.ligne = ligne; nouvelle_alloc.tableau = tableau; allocations[pointeur] = nouvelle_alloc; fichier_sortie << "++ 0x" << pointeur << " | " << std::setw(7) << std::setfill(' ') << static_cast(nouvelle_alloc.taille) << " octets" << " | " << nouvelle_alloc.fichier.nom_complet() << " (" << nouvelle_alloc.ligne << ")" << std::endl; return pointeur; } void GESTIONNAIRE_MEMOIRE::liberer(void* pointeur, bool tableau) { ALLOCATIONS::iterator i = allocations.find(pointeur); if(i == allocations.end()) { //On rentre dans ce block si on a pas trouvé d'allocation //correspondant à la désallocation, cela arrive souvent car le //delete surchargé le reste tout le temps, dans ce cas on le fait se //comporter comme un simple delete (un coup de free) et on quitte free(pointeur); return; } fichier_sortie << "-- 0x" << pointeur << " | " << std::setw(7) << std::setfill(' ') << static_cast(i->second.taille) << " octets" << " | " << i->second.fichier.nom_complet() << " (" << i->second.ligne << ")" << std::endl; allocations.erase(i); pile_desalloc.pop(); free(pointeur); } void GESTIONNAIRE_MEMOIRE::desalloc_suivante(const FICHIER& fichier, int ligne) { IALLOC desallocation; desallocation.fichier = fichier; desallocation.ligne = ligne; pile_desalloc.push(desallocation); } }