// ============================================================== // This file is part of Glest Shared Library (www.glest.org) // // Copyright (C) 2001-2008 Martiņo Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published // by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version // ============================================================== #include "leak_dumper.h" #ifdef SL_LEAK_DUMP AllocInfo::AllocInfo(){ ptr= NULL; file= ""; line= -1; bytes= -1; array= false; free= true; } AllocInfo::AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array){ this->ptr= ptr; this->file= file; this->line= line; this->bytes= bytes; this->array= array; free= false; } // ===================================================== // class AllocRegistry // ===================================================== // ===================== PRIVATE ======================= AllocRegistry::AllocRegistry(){ allocCount= 0; allocBytes= 0; nonMonitoredCount= 0; nonMonitoredBytes= 0; } // ===================== PUBLIC ======================== AllocRegistry &AllocRegistry::getInstance(){ static AllocRegistry allocRegistry; return allocRegistry; } AllocRegistry::~AllocRegistry(){ dump("leak_dump.log"); } void AllocRegistry::allocate(AllocInfo info){ ++allocCount; allocBytes+= info.bytes; unsigned hashCode= reinterpret_cast(info.ptr) % maxAllocs; for(int i=hashCode; i(ptr) % maxAllocs; for(int i=hashCode; i