@@ -34,28 +34,14 @@ static inline size_t DynamicUsage(const float& v) { return 0; }
3434static inline size_t DynamicUsage (const double & v) { return 0 ; }
3535template <typename X> static inline size_t DynamicUsage (X * const &v) { return 0 ; }
3636template <typename X> static inline size_t DynamicUsage (const X * const &v) { return 0 ; }
37- template <typename X, typename Y> static inline size_t DynamicUsage (std::pair<X, Y> &p) { return 0 ; }
3837
3938/* * Compute the memory used for dynamically allocated but owned data structures.
4039 * For generic data types, this is *not* recursive. DynamicUsage(vector<vector<int> >)
4140 * will compute the memory used for the vector<int>'s, but not for the ints inside.
4241 * This is for efficiency reasons, as these functions are intended to be fast. If
4342 * application data structures require more accurate inner accounting, they should
44- * use RecursiveDynamicUsage, iterate themselves, or use more efficient caching +
45- * updating on modification.
43+ * iterate themselves, or use more efficient caching + updating on modification.
4644 */
47- template <typename X> static size_t DynamicUsage (const std::vector<X>& v);
48- template <typename X> static size_t DynamicUsage (const std::set<X>& s);
49- template <typename X, typename Y> static size_t DynamicUsage (const std::map<X, Y>& m);
50- template <typename X, typename Y> static size_t DynamicUsage (const boost::unordered_set<X, Y>& s);
51- template <typename X, typename Y, typename Z> static size_t DynamicUsage (const boost::unordered_map<X, Y, Z>& s);
52- template <typename X> static size_t DynamicUsage (const X& x);
53-
54- template <typename X> static size_t RecursiveDynamicUsage (const std::vector<X>& v);
55- template <typename X> static size_t RecursiveDynamicUsage (const std::set<X>& v);
56- template <typename X, typename Y> static size_t RecursiveDynamicUsage (const std::map<X, Y>& v);
57- template <typename X, typename Y> static size_t RecursiveDynamicUsage (const std::pair<X, Y>& v);
58- template <typename X> static size_t RecursiveDynamicUsage (const X& v);
5945
6046static inline size_t MallocUsage (size_t alloc)
6147{
@@ -88,54 +74,18 @@ static inline size_t DynamicUsage(const std::vector<X>& v)
8874 return MallocUsage (v.capacity () * sizeof (X));
8975}
9076
91- template <typename X>
92- static inline size_t RecursiveDynamicUsage (const std::vector<X>& v)
93- {
94- size_t usage = DynamicUsage (v);
95- BOOST_FOREACH (const X& x, v) {
96- usage += RecursiveDynamicUsage (x);
97- }
98- return usage;
99- }
100-
10177template <typename X>
10278static inline size_t DynamicUsage (const std::set<X>& s)
10379{
10480 return MallocUsage (sizeof (stl_tree_node<X>)) * s.size ();
10581}
10682
107- template <typename X>
108- static inline size_t RecursiveDynamicUsage (const std::set<X>& v)
109- {
110- size_t usage = DynamicUsage (v);
111- BOOST_FOREACH (const X& x, v) {
112- usage += RecursiveDynamicUsage (x);
113- }
114- return usage;
115- }
116-
11783template <typename X, typename Y>
11884static inline size_t DynamicUsage (const std::map<X, Y>& m)
11985{
12086 return MallocUsage (sizeof (stl_tree_node<std::pair<const X, Y> >)) * m.size ();
12187}
12288
123- template <typename X, typename Y>
124- static inline size_t RecursiveDynamicUsage (const std::map<X, Y>& v)
125- {
126- size_t usage = DynamicUsage (v);
127- for (typename std::map<X, Y>::const_iterator it = v.begin (); it != v.end (); it++) {
128- usage += RecursiveDynamicUsage (*it);
129- }
130- return usage;
131- }
132-
133- template <typename X, typename Y>
134- static inline size_t RecursiveDynamicUsage (const std::pair<X, Y>& v)
135- {
136- return RecursiveDynamicUsage (v.first ) + RecursiveDynamicUsage (v.second );
137- }
138-
13989// Boost data structures
14090
14191template <typename X>
@@ -157,20 +107,6 @@ static inline size_t DynamicUsage(const boost::unordered_map<X, Y, Z>& m)
157107 return MallocUsage (sizeof (boost_unordered_node<std::pair<const X, Y> >)) * m.size () + MallocUsage (sizeof (void *) * m.bucket_count ());
158108}
159109
160- // Dispatch to class method as fallback
161-
162- template <typename X>
163- static inline size_t DynamicUsage (const X& x)
164- {
165- return x.DynamicMemoryUsage ();
166- }
167-
168- template <typename X>
169- static inline size_t RecursiveDynamicUsage (const X& x)
170- {
171- return DynamicUsage (x);
172- }
173-
174110}
175111
176112#endif
0 commit comments