5 #ifndef BITCOIN_MEMUSAGE_H
6 #define BITCOIN_MEMUSAGE_H
14 #include <boost/unordered_set.hpp>
15 #include <boost/unordered_map.hpp>
21 static size_t MallocUsage(
size_t alloc);
30 template<
typename X>
static size_t DynamicUsage(
const std::vector<X>& v);
31 template<
typename X>
static size_t DynamicUsage(
const std::set<X>& s);
32 template<
typename X,
typename Y>
static size_t DynamicUsage(
const std::map<X, Y>& m);
33 template<
typename X,
typename Y>
static size_t DynamicUsage(
const boost::unordered_set<X, Y>& s);
34 template<
typename X,
typename Y,
typename Z>
static size_t DynamicUsage(
const boost::unordered_map<X, Y, Z>& s);
35 template<
typename X>
static size_t DynamicUsage(
const X& x);
37 static inline size_t MallocUsage(
size_t alloc)
42 }
else if (
sizeof(
void*) == 8) {
43 return ((alloc + 31) >> 4) << 4;
44 }
else if (
sizeof(
void*) == 4) {
45 return ((alloc + 15) >> 3) << 3;
65 static inline size_t DynamicUsage(
const std::vector<X>& v)
67 return MallocUsage(v.capacity() *
sizeof(
X));
70 template<
unsigned int N,
typename X,
typename S,
typename D>
77 static inline size_t DynamicUsage(
const std::set<X>& s)
79 return MallocUsage(
sizeof(stl_tree_node<X>)) * s.size();
82 template<
typename X,
typename Y>
83 static inline size_t DynamicUsage(
const std::map<X, Y>& m)
85 return MallocUsage(
sizeof(stl_tree_node<std::pair<const X, Y> >)) * m.size();
97 template<
typename X,
typename Y>
98 static inline size_t DynamicUsage(
const boost::unordered_set<X, Y>& s)
100 return MallocUsage(
sizeof(
boost_unordered_node<X>)) * s.size() + MallocUsage(
sizeof(
void*) * s.bucket_count());
103 template<
typename X,
typename Y,
typename Z>
104 static inline size_t DynamicUsage(
const boost::unordered_map<X, Y, Z>& m)
106 return MallocUsage(
sizeof(boost_unordered_node<std::pair<const X, Y> >)) * m.size() + MallocUsage(
sizeof(
void*) * m.bucket_count());
112 static inline size_t DynamicUsage(
const X& x)
114 return x.DynamicMemoryUsage();