Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MLD.h"
- std::vector<MemLeakInfo> MemoryInformation;
- std::vector<MemLeakInfo> BadCalls;
- #define new MY_DEBUG_NEW
- #ifdef _DEBUG
- void* operator new(unsigned int Size, int Line, const char* File)
- {
- void* ptr = (void*)malloc(Size);
- if(ptr)
- {
- AddMemoryInformation( (unsigned int)ptr, Line, Size, *File, MemoryInformation);
- }
- else
- {
- AddMemoryInformation( 0, Line, 0, *File, BadCalls);
- };
- return ptr;
- };
- void* operator new[](unsigned int Size, int Line, const char* File)
- {
- void* ptr = (void*)malloc(Size);
- if(ptr)
- {
- AddMemoryInformation( (unsigned int)ptr, Line, Size, *File, MemoryInformation);
- }
- else
- {
- AddMemoryInformation( 0, Line, 0, *File, BadCalls);
- };
- return ptr;
- };
- void operator delete(void* ptr)
- {
- free(ptr);
- RemoveMemoryInformation( (unsigned int)ptr);
- };
- void operator delete[](void* ptr)
- {
- free(ptr);
- RemoveMemoryInformation( (unsigned int)ptr);
- };
- #endif
- void AddMemoryInformation(unsigned int Address, unsigned int Line, unsigned int Size, unsigned char File, std::vector<MemLeakInfo> &Vect)
- {
- MemLeakInfo NewMemLeak;
- NewMemLeak.addr = Address;
- NewMemLeak.line = Line;
- NewMemLeak.size = Size;
- NewMemLeak.file = File;
- Vect.push_back(NewMemLeak);
- };
- void RemoveMemoryInformation(unsigned int Address)
- {
- std::vector<MemLeakInfo>::iterator Iter;
- for(Iter = MemoryInformation.begin(); Iter != MemoryInformation.end(); Iter++)
- {
- if( (*Iter).addr = Address)
- {
- Iter = MemoryInformation.erase( (Iter) );
- break;
- };
- };
- };
- void DumpInformation()
- {
- if( MemoryInformation.size() > 0)
- {
- std::vector<MemLeakInfo>::iterator MIter;
- std::ofstream File("MemoryDumpInformation.txt");
- for(MIter = MemoryInformation.begin(); MIter != MemoryInformation.end(); MIter++)
- {
- File << "Address:" + (*MIter).addr;
- File << " Size:" + (*MIter).size;
- File << " File:" + (*MIter).file;
- File << " Line:" + (*MIter).line;
- };
- File.close();
- };
- if(BadCalls.size() > 0)
- {
- std::vector<MemLeakInfo>::iterator BIter;
- std::ofstream File("BadCalls.txt");
- for(BIter = BadCalls.begin(); BIter != BadCalls.end(); BIter++)
- {
- File << "File:" + (*BIter).file;
- File << " Line:" + (*BIter).line;
- };
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement