5 #ifndef FABCOIN_MEMUSAGE_H 6 #define FABCOIN_MEMUSAGE_H 15 #include <unordered_map> 16 #include <unordered_set> 23 static size_t MallocUsage(
size_t alloc);
26 static inline size_t DynamicUsage(
const int8_t& v) {
return 0; }
27 static inline size_t DynamicUsage(
const uint8_t& v) {
return 0; }
28 static inline size_t DynamicUsage(
const int16_t& v) {
return 0; }
29 static inline size_t DynamicUsage(
const uint16_t& v) {
return 0; }
30 static inline size_t DynamicUsage(
const int32_t& v) {
return 0; }
31 static inline size_t DynamicUsage(
const uint32_t& v) {
return 0; }
32 static inline size_t DynamicUsage(
const int64_t& v) {
return 0; }
33 static inline size_t DynamicUsage(
const uint64_t& v) {
return 0; }
34 static inline size_t DynamicUsage(
const float& v) {
return 0; }
35 static inline size_t DynamicUsage(
const double& v) {
return 0; }
36 template<
typename X>
static inline size_t DynamicUsage(
X *
const &v) {
return 0; }
37 template<
typename X>
static inline size_t DynamicUsage(
const X *
const &v) {
return 0; }
47 static inline size_t MallocUsage(
size_t alloc)
52 }
else if (
sizeof(
void*) == 8) {
53 return ((alloc + 31) >> 4) << 4;
54 }
else if (
sizeof(
void*) == 4) {
55 return ((alloc + 15) >> 3) << 3;
84 static inline size_t DynamicUsage(
const std::vector<X>& v)
86 return MallocUsage(v.capacity() *
sizeof(
X));
89 template<
unsigned int N,
typename X,
typename S,
typename D>
95 template<
typename X,
typename Y>
96 static inline size_t DynamicUsage(
const std::set<X, Y>& s)
101 template<
typename X,
typename Y>
102 static inline size_t IncrementalDynamicUsage(
const std::set<X, Y>& s)
107 template<
typename X,
typename Y,
typename Z>
108 static inline size_t DynamicUsage(
const std::map<X, Y, Z>& m)
110 return MallocUsage(
sizeof(
stl_tree_node<std::pair<const X, Y> >)) * m.size();
113 template<
typename X,
typename Y,
typename Z>
114 static inline size_t IncrementalDynamicUsage(
const std::map<X, Y, Z>& m)
116 return MallocUsage(
sizeof(
stl_tree_node<std::pair<const X, Y> >));
121 template<
typename X,
typename Y>
127 template<
typename X,
typename Y>
130 return MallocUsage(
sizeof(
stl_tree_node<std::pair<const X*, Y> >));
134 static inline size_t DynamicUsage(
const std::unique_ptr<X>& p)
136 return p ? MallocUsage(
sizeof(
X)) : 0;
140 static inline size_t DynamicUsage(
const std::shared_ptr<X>& p)
155 template<
typename X,
typename Y>
156 static inline size_t DynamicUsage(
const std::unordered_set<X, Y>& s)
158 return MallocUsage(
sizeof(
unordered_node<X>)) * s.size() + MallocUsage(
sizeof(
void*) * s.bucket_count());
161 template<
typename X,
typename Y,
typename Z>
162 static inline size_t DynamicUsage(
const std::unordered_map<X, Y, Z>& m)
164 return MallocUsage(
sizeof(
unordered_node<std::pair<const X, Y> >)) * m.size() + MallocUsage(
sizeof(
void*) * m.bucket_count());
169 #endif // FABCOIN_MEMUSAGE_H
assert(len-trim+(2 *lenIndices)<=WIDTH)
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
size_t allocated_memory() const