aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/defs.cc
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2008-02-02 15:43:00 +0000
committerErik Schnetter <schnetter@cct.lsu.edu>2008-02-02 15:43:00 +0000
commit1beb710e75a868f71b74ca5a2b13017593a4469e (patch)
treed9d916cb78ae9b3ee1bd824fbfc9d32401892d2d /Carpet/CarpetLib/src/defs.cc
parentd2d5504fd8975ae714d70cbdda4805d49f0c5bf5 (diff)
CarpetLib: Add function memoryof to measure size of data structures
Add an overloaded function memoryof which measures the size in bytes of CarpetLib's data structures. darcs-hash:20080202154302-dae7b-de41c79cb04617327695fae27928c05c5d431ee8.gz
Diffstat (limited to 'Carpet/CarpetLib/src/defs.cc')
-rw-r--r--Carpet/CarpetLib/src/defs.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/defs.cc b/Carpet/CarpetLib/src/defs.cc
index 1dd6cb34f..a3d43d88d 100644
--- a/Carpet/CarpetLib/src/defs.cc
+++ b/Carpet/CarpetLib/src/defs.cc
@@ -81,6 +81,63 @@ void consume (istream& is, const char * const s) {
+// Container memory usage
+template <class T>
+size_t
+memoryof (list<T> const & c)
+{
+ size_t s = sizeof c;
+ for (typename list<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Assume that there are two pointers per list element, pointing
+ // to the previous and next element, respectively
+ s += 2 * sizeof (void *) + memoryof(*i);
+ }
+ return s;
+}
+
+template <class T>
+size_t
+memoryof (set<T> const & c)
+{
+ size_t s = sizeof c;
+ for (typename set<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Assume that there are three pointers per list element, forming
+ // a tree structure
+ s += 3 * sizeof (void *) + memoryof(*i);
+ }
+ return s;
+}
+
+template <class T>
+size_t
+memoryof (stack<T> const & c)
+{
+ size_t s = sizeof c;
+#if 0
+ for (typename stack<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Assume that a stack is stored in an efficient manner
+ s += memoryof(*i);
+ }
+#endif
+ // Cannot access elements... a stack is LIFO!
+ s += c.size() * sizeof (T);
+ return s;
+}
+
+template <class T>
+size_t
+memoryof (vector<T> const & c)
+{
+ size_t s = sizeof c;
+ for (typename vector<T>::const_iterator i=c.begin(); i!=c.end(); ++i) {
+ // Vectors are stored contiguously
+ s += memoryof(*i);
+ }
+ return s;
+}
+
+
+
// Vector input
template<class T>
istream& input (istream& is, vector<T>& v) {
@@ -166,12 +223,41 @@ ostream& output (ostream& os, const vector<T>& v) {
#include "bbox.hh"
#include "bboxset.hh"
+#include "dh.hh"
+#include "gdata.hh"
+#include "ggf.hh"
+#include "region.hh"
+#include "th.hh"
#include "vect.hh"
template int ipow (int x, int y);
template CCTK_REAL ipow (CCTK_REAL x, int y);
template vect<int,3> ipow (vect<int,3> x, int y);
+template size_t memoryof (list<bbox<int,3> > const & l);
+template size_t memoryof (list<vect<int,3> > const & l);
+template size_t memoryof (list<dh*> const & l);
+template size_t memoryof (list<ggf*> const & l);
+template size_t memoryof (list<th*> const & l);
+template size_t memoryof (stack<void*> const & s);
+template size_t memoryof (vector<bool> const & v);
+template size_t memoryof (vector<int> const & v);
+template size_t memoryof (vector<CCTK_REAL> const & v);
+template size_t memoryof (vector<bbox<int,3> > const & v);
+template size_t memoryof (vector<vect<int,3> > const & v);
+template size_t memoryof (vector<pseudoregion_t> const & v);
+template size_t memoryof (vector<region_t> const & v);
+template size_t memoryof (vector<sendrecv_pseudoregion_t> const & v);
+template size_t memoryof (vector<vector<int> > const & v);
+template size_t memoryof (vector<vector<CCTK_REAL> > const & v);
+template size_t memoryof (vector<vector<bbox<int,3> > > const & v);
+template size_t memoryof (vector<vector<dh::dboxes> > const & v);
+template size_t memoryof (vector<vector<region_t> > const & v);
+template size_t memoryof (vector<vector<vector<dh::dboxes> > > const & v);
+template size_t memoryof (vector<vector<vector<region_t> > > const & v);
+template size_t memoryof (vector<vector<vector<gdata*> > > const & v);
+template size_t memoryof (vector<vector<vector<vector<gdata*> > > > const & v);
+
template istream& input (istream& os, vector<int>& v);
template istream& input (istream& os, vector<CCTK_REAL>& v);
template istream& input (istream& os, vector<bbox<int,3> >& v);