5 #ifndef BITCOIN_MEMUSAGE_H
6 #define BITCOIN_MEMUSAGE_H
19 #include <unordered_map>
20 #include <unordered_set>
40 template<
typename X>
static inline size_t DynamicUsage(
X *
const &v) {
return 0; }
41 template<
typename X>
static inline size_t DynamicUsage(
const X *
const &v) {
return 0; }
56 }
else if (
sizeof(
void*) == 8) {
57 return ((alloc + 31) >> 4) << 4;
58 }
else if (
sizeof(
void*) == 4) {
59 return ((alloc + 15) >> 3) << 3;
93 template<
unsigned int N,
typename X,
typename S,
typename D>
99 template<
typename X,
typename Y>
105 template<
typename X,
typename Y>
111 template<
typename X,
typename Y,
typename Z>
117 template<
typename X,
typename Y,
typename Z>
125 template<
typename X,
typename Y>
131 template<
typename X,
typename Y>
174 template<
typename X,
typename Y>
180 template<
typename X,
typename Y,
typename Z>
181 static inline size_t DynamicUsage(
const std::unordered_map<X, Y, Z>& m)
186 template <
class Key,
class T,
class Hash,
class Pred, std::
size_t MAX_BLOCK_SIZE_BYTES, std::
size_t ALIGN_BYTES>
192 MAX_BLOCK_SIZE_BYTES,
195 auto* pool_resource =
m.get_allocator().resource();
199 size_t estimated_list_node_size =
MallocUsage(
sizeof(
void*) * 3);
200 size_t usage_resource = estimated_list_node_size * pool_resource->NumAllocatedChunks();
201 size_t usage_chunks =
MallocUsage(pool_resource->ChunkSizeBytes()) * pool_resource->NumAllocatedChunks();
202 return usage_resource + usage_chunks +
MallocUsage(
sizeof(
void*) *
m.bucket_count());
Forwards all allocations/deallocations to the PoolResource.
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.