MADNESS  version 0.9
worldmem.h
Go to the documentation of this file.
1 #ifndef MADNESS_WORLD_WORLDMEM_H__INCLUDED
2 #define MADNESS_WORLD_WORLDMEM_H__INCLUDED
3 
4 /*
5  This file is part of MADNESS.
6 
7  Copyright (C) 2007,2010 Oak Ridge National Laboratory
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  For more information please contact:
24 
25  Robert J. Harrison
26  Oak Ridge National Laboratory
27  One Bethel Valley Road
28  P.O. Box 2008, MS-6367
29 
30  email: harrisonrj@ornl.gov
31  tel: 865-241-3937
32  fax: 865-572-0680
33 
34 
35  $Id: world.cc 454 2008-01-26 03:08:15Z rjharrison $
36 */
37 
38 #include <madness/madness_config.h>
39 #ifdef WORLD_GATHER_MEM_STATS
40 #include <new>
41 #endif // WORLD_GATHER_MEM_STATS
42 #include <cstddef>
43 
44 namespace madness {
45 
47 
53  class WorldMemInfo {
54 #ifdef WORLD_GATHER_MEM_STATS
55  friend void* ::operator new(size_t size) throw (std::bad_alloc);
56  friend void ::operator delete(void *p) throw();
57 #endif
58  private:
60  void do_new(void *p, std::size_t size);
61 
63  void do_del(void *p, std::size_t size);
64 
65  public:
66  static const unsigned long overhead = 4*sizeof(long) + 16;
68  unsigned long num_new_calls;
69  unsigned long num_del_calls;
70  unsigned long cur_num_frags;
71  unsigned long max_num_frags;
72  unsigned long cur_num_bytes;
73  unsigned long max_num_bytes;
74  unsigned long max_mem_limit;
75  bool trace;
76 
78  void print() const;
79 
81  void reset();
82 
84  void set_trace(bool trace) {
85  this->trace = trace;
86  }
87 
89  void set_max_mem_limit(unsigned long max_mem_limit) {
90  this->max_mem_limit = max_mem_limit;
91  }
92  };
93 
95  WorldMemInfo* world_mem_info();
96 }
97 #endif // MADNESS_WORLD_WORLDMEM_H__INCLUDED
unsigned long num_new_calls
If you add new stats be sure that the initialization in worldmem.cc is OK.
Definition: worldmem.h:68
void print() const
Prints memory use statistics to std::cout.
Definition: worldmem.cc:89
unsigned long max_num_bytes
Lifetime maximum number of allocated bytes.
Definition: worldmem.h:73
void reset()
Resets all counters to zero.
Definition: worldmem.cc:103
unsigned long max_mem_limit
if size+cur_num_bytes>max_mem_limit new will throw MadnessException
Definition: worldmem.h:74
bool trace
Definition: worldmem.h:75
unsigned long cur_num_frags
Current number of allocated fragments.
Definition: worldmem.h:70
void set_trace(bool trace)
If trace is set true a message is printed for every new and delete.
Definition: worldmem.h:84
unsigned long max_num_frags
Lifetime maximum number of allocated fragments.
Definition: worldmem.h:71
unsigned long cur_num_bytes
Current amount of allocated memory in bytes.
Definition: worldmem.h:72
Used to output memory statistics and control tracing, etc.
Definition: worldmem.h:53
void set_max_mem_limit(unsigned long max_mem_limit)
Set the maximum memory limit (trying to allocate more will throw MadnessException) ...
Definition: worldmem.h:89
WorldMemInfo * world_mem_info()
Returns pointer to internal structure.
Definition: worldmem.cc:65
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
static const unsigned long overhead
Definition: worldmem.h:66
unsigned long num_del_calls
Counts calls to delete.
Definition: worldmem.h:69