Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

misc/memhist.h

00001 #ifndef MISC_MEMHIST_H
00002 #define MISC_MEMHIST_H
00003 
00004 /*
00005 
00006   GLT OpenGL C++ Toolkit (LGPL)
00007   Copyright (C) 2000-2002 Nigel Stewart  
00008 
00009   Email: nigels.com@gmail.com   
00010   WWW:   http://www.nigels.com/glt/
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 */
00027 
00028 #ifndef DOXYGEN
00029 
00043 #ifdef WIN32
00044 #pragma warning(disable : 4786)     // Lengthy STL symbols
00045 #endif
00046 
00047 #include <cstdlib>
00048 #include <list>
00049 #include <map>
00050 #include <iosfwd>
00051 
00059 class MemoryEvent
00060 {
00061     friend class MemoryModel;       // Memory model needs to see private members
00062 
00063 public:
00064     MemoryEvent(void *ptr,size_t size);             // new
00065     MemoryEvent(void *ptr);                         // delete
00066 
00067 private:
00068     void   *_ptr;
00069     size_t  _size;
00070     bool    _new;
00071 };
00072 
00080 class MemoryEventHistory : public std::list<MemoryEvent>
00081 {
00082 public:
00083     MemoryEventHistory();
00084     MemoryEventHistory(std::istream &is);
00085 
00086     void summary(std::ostream &os) const;
00087 };
00088 
00096 class MemoryModel 
00097 {
00098 public:
00099     MemoryModel();
00100 
00101     void apply(const MemoryEvent &event);
00102 
00103     size_t minAddress() const;
00104     size_t maxAddress() const;
00105     size_t addressSpace() const;
00106     size_t blocks() const;
00107     size_t memoryUsed() const;
00108     size_t maxBlocks() const;
00109     size_t maxMemory() const;
00110 
00111     size_t numAllocations() const;
00112     size_t numFree() const;
00113     size_t numFreeNull() const;
00114     size_t numFreeInvalid() const;
00115 
00116 private:
00117     std::map<size_t, size_t, std::less<size_t> >            _allocated;
00118     size_t                                                  _minAddress,_maxAddress;
00119     size_t                                                  _memoryUsed;
00120     size_t                                                  _maxBlocks;
00121     size_t                                                  _maxMemory;
00122 
00123     size_t                                                  _numAllocations;
00124     size_t                                                  _numFree;
00125     size_t                                                  _numFreeNull;
00126     size_t                                                  _numFreeInvalid;
00127 };
00128 
00129 #endif
00130 #endif

Generated on Tue Nov 5 11:11:05 2002 for GLT by doxygen1.2.18