src/include/win32/base/MemTracker.h

00001 /*
00002  * Copyright (C) 2003-2007 Funambol
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #ifndef INCL_WIN32_MEMTRACKER
00020 #define INCL_WIN32_MEMTRACKER
00021 
00024 #define MAX_LENGHT_FILE     256
00025 
00026 #include <stdio.h>
00027 #include "base/Log.h"
00028 #include "base/util/utils.h"
00029 
00030 
00031 
00032 /*
00033  * Class to menage memory leaks tracking.
00034  * Each memory allocation information is stored into 'allocList' 
00035  * (redefining new operator)
00036  * Need to set MALLOC_DEBUG into preprocessor definitions.
00037 */
00038 class MemTracker {
00039 
00040 private:
00041 
00042     // The list of AllocInfo elements.
00043     ArrayList allocList;
00044 
00045     // to enable-disble memory leaks tracking
00046     bool tracking;
00047 
00048 public:
00049 
00050 
00051     MemTracker(bool useMemTracking);
00052     ~MemTracker();
00053 
00054     void addTrack(DWORD addr,  DWORD asize,  const char *fname, DWORD lnum);
00055     void removeTrack(DWORD addr);
00056     void dumpUnfreed();
00057 
00058     void enableMemTracker();
00059     void disableMemTracker();
00060 
00061     bool isMemTracking();
00062 
00063 };
00064 
00065 
00066 
00067 
00068 // Class to store alloc informations.
00069 class AllocInfo : public ArrayElement {
00070 
00071 public:
00072     DWORD       address;
00073     DWORD       size;
00074     char        file[MAX_LENGHT_FILE];
00075     DWORD       line;
00076 
00077     ArrayElement* clone();  
00078 };
00079 
00080 
00082 #endif

Generated on Fri Apr 27 12:29:19 2007 for Funambol C++ Client Library by  doxygen 1.5.2