source: molecuilder/src/memoryusageobserver.hpp@ afbb6c0

Last change on this file since afbb6c0 was 729279, checked in by metzler <metzler@…>, 16 years ago

#22 Write a critical exit function

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 * \file memoryusageobserver.hpp
3 *
4 * This class represents a Singleton for observing memory usage.
5 */
6#ifndef MEMORYUSAGEOBSERVER_HPP_
7#define MEMORYUSAGEOBSERVER_HPP_
8
9using namespace std;
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <map>
17#include <iostream>
18#include <iomanip>
19#include <fstream>
20#include <sstream>
21#include <math.h>
22#include <string>
23#include <typeinfo>
24
25class MemoryUsageObserver {
26public:
27 static MemoryUsageObserver* getInstance();
28 static void purgeInstance();
29 void addMemory(void* pointer, size_t size);
30 void removeMemory(void* pointer, const char *msg = NULL);
31 size_t getUsedMemorySize();
32 size_t getMaximumUsedMemory();
33 map<void*, size_t> getPointersToAllocatedMemory();
34
35protected:
36 /** Do not call this constructor directly, use getInstance() instead. */
37 MemoryUsageObserver();
38 /** Do not call this destructor directly, use purgeInstance() instead. */
39 ~MemoryUsageObserver();
40
41private:
42 static MemoryUsageObserver* instance;
43 map<void*, size_t> memoryUsers;
44 size_t totalSize, maximumSize;
45};
46#endif /*MEMORYUSAGEOBSERVER_HPP_*/
Note: See TracBrowser for help on using the repository browser.