5 #ifndef BITCOIN_MEMUSAGE_H 6 #define BITCOIN_MEMUSAGE_H 20 #include <unordered_map> 21 #include <unordered_set> 41 template<
typename X>
static inline size_t DynamicUsage(
X *
const &v) {
return 0; }
42 template<
typename X>
static inline size_t DynamicUsage(
const X *
const &v) {
return 0; }
57 }
else if (
sizeof(
void*) == 8) {
58 return ((alloc + 31) >> 4) << 4;
59 }
else if (
sizeof(
void*) == 4) {
60 return ((alloc + 15) >> 3) << 3;
88 template<
typename T,
typename Allocator>
89 static inline size_t DynamicUsage(
const std::vector<T, Allocator>& v)
96 const char* s_ptr =
reinterpret_cast<const char*
>(&
s);
100 if (!std::less{}(
s.data(), s_ptr) && !std::greater{}(
s.data() +
s.size(), s_ptr +
sizeof(
s))) {
106 template<
unsigned int N,
typename X,
typename S,
typename D>
112 template<
typename X,
typename Y>
118 template<
typename X,
typename Y>
124 template<
typename X,
typename Y,
typename Z>
130 template<
typename X,
typename Y,
typename Z>
138 template<
typename X,
typename Y>
144 template<
typename X,
typename Y>
187 template<
typename X,
typename Y>
193 template<
typename X,
typename Y,
typename Z>
194 static inline size_t DynamicUsage(
const std::unordered_map<X, Y, Z>& m)
199 template <
class Key,
class T,
class Hash,
class Pred, std::
size_t MAX_BLOCK_SIZE_BYTES, std::
size_t ALIGN_BYTES>
205 MAX_BLOCK_SIZE_BYTES,
208 auto* pool_resource =
m.get_allocator().resource();
212 size_t estimated_list_node_size =
MallocUsage(
sizeof(
void*) * 3);
213 size_t usage_resource = estimated_list_node_size * pool_resource->NumAllocatedChunks();
214 size_t usage_chunks =
MallocUsage(pool_resource->ChunkSizeBytes()) * pool_resource->NumAllocatedChunks();
215 return usage_resource + usage_chunks +
MallocUsage(
sizeof(
void*) *
m.bucket_count());
220 #endif // BITCOIN_MEMUSAGE_H
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
size_t allocated_memory() const
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
Forwards all allocations/deallocations to the PoolResource.
static size_t IncrementalDynamicUsage(const std::set< X, Y > &s)
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
#define T(expected, seed, data)