5#ifndef BITCOIN_MEMUSAGE_H
6#define BITCOIN_MEMUSAGE_H
17#include <unordered_map>
18#include <unordered_set>
57template <
typename X>
static inline size_t DynamicUsage(X *
const &v) {
60template <
typename X>
static inline size_t DynamicUsage(
const X *
const &v) {
77 }
else if (
sizeof(
void *) == 8) {
78 return ((alloc + 31) >> 4) << 4;
79 }
else if (
sizeof(
void *) == 4) {
80 return ((alloc + 15) >> 3) << 3;
112template <
unsigned int N,
typename X,
typename S,
typename D>
117template <
typename X,
typename Y>
122template <
typename X,
typename Y>
127template <
typename X,
typename Y,
typename Z>
132template <
typename X,
typename Y,
typename Z>
139template <
typename X,
typename Y>
145template <
typename X,
typename Y>
171template <
typename X,
typename Y>
177template <
typename X,
typename Y,
typename Z>
178static inline size_t DynamicUsage(
const std::unordered_map<X, Y, Z> &m) {
184template <
class Key,
class T,
class Hash,
class Pred,
185 std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES>
187 const std::unordered_map<Key, T,
Hash, Pred,
189 MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>>
191 auto *pool_resource = m.get_allocator().resource();
195 size_t estimated_list_node_size =
MallocUsage(
sizeof(
void *) * 3);
196 size_t usage_resource =
197 estimated_list_node_size * pool_resource->NumAllocatedChunks();
198 size_t usage_chunks =
MallocUsage(pool_resource->ChunkSizeBytes()) *
199 pool_resource->NumAllocatedChunks();
200 return usage_resource + usage_chunks +
Forwards all allocations/deallocations to the PoolResource.
Map whose keys are pointers, but are compared by their dereferenced values.
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
size_t allocated_memory() const
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
static size_t IncrementalDynamicUsage(const std::set< X, Y > &s)
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
void * class_type
Various platforms use different sized counters here.