5#ifndef BITCOIN_MEMUSAGE_H
6#define BITCOIN_MEMUSAGE_H
18#include <unordered_map>
19#include <unordered_set>
58template <
typename X>
static inline size_t DynamicUsage(X *
const &v) {
61template <
typename X>
static inline size_t DynamicUsage(
const X *
const &v) {
78 }
else if (
sizeof(
void *) == 8) {
79 return ((alloc + 31) >> 4) << 4;
80 }
else if (
sizeof(
void *) == 4) {
81 return ((alloc + 15) >> 3) << 3;
113template <
unsigned int N,
typename X,
typename S,
typename D>
118template <
typename X,
typename Y>
123template <
typename X,
typename Y>
128template <
typename X,
typename Y,
typename Z>
133template <
typename X,
typename Y,
typename Z>
140template <
typename X,
typename Y>
146template <
typename X,
typename Y>
172template <
typename X>
static inline size_t DynamicUsage(
const std::list<X> &l) {
183template <
typename X,
typename Y>
189template <
typename X,
typename Y,
typename Z>
190static inline size_t DynamicUsage(
const std::unordered_map<X, Y, Z> &m) {
196template <
class Key,
class T,
class Hash,
class Pred,
197 std::size_t MAX_BLOCK_SIZE_BYTES, std::size_t ALIGN_BYTES>
199 const std::unordered_map<Key, T,
Hash, Pred,
201 MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES>>
203 auto *pool_resource = m.get_allocator().resource();
207 size_t estimated_list_node_size =
MallocUsage(
sizeof(
void *) * 3);
208 size_t usage_resource =
209 estimated_list_node_size * pool_resource->NumAllocatedChunks();
210 size_t usage_chunks =
MallocUsage(pool_resource->ChunkSizeBytes()) *
211 pool_resource->NumAllocatedChunks();
212 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.