Bitcoin Core 28.99.0
P2P Digital Currency
core_memusage.h
Go to the documentation of this file.
1// Copyright (c) 2015-2018 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_CORE_MEMUSAGE_H
6#define BITCOIN_CORE_MEMUSAGE_H
7
9#include <primitives/block.h>
10#include <memusage.h>
11
12static inline size_t RecursiveDynamicUsage(const CScript& script) {
14}
15
16static inline size_t RecursiveDynamicUsage(const COutPoint& out) {
17 return 0;
18}
19
20static inline size_t RecursiveDynamicUsage(const CTxIn& in) {
22 for (std::vector<std::vector<unsigned char> >::const_iterator it = in.scriptWitness.stack.begin(); it != in.scriptWitness.stack.end(); it++) {
23 mem += memusage::DynamicUsage(*it);
24 }
25 return mem;
26}
27
28static inline size_t RecursiveDynamicUsage(const CTxOut& out) {
29 return RecursiveDynamicUsage(out.scriptPubKey);
30}
31
32static inline size_t RecursiveDynamicUsage(const CTransaction& tx) {
34 for (std::vector<CTxIn>::const_iterator it = tx.vin.begin(); it != tx.vin.end(); it++) {
35 mem += RecursiveDynamicUsage(*it);
36 }
37 for (std::vector<CTxOut>::const_iterator it = tx.vout.begin(); it != tx.vout.end(); it++) {
38 mem += RecursiveDynamicUsage(*it);
39 }
40 return mem;
41}
42
43static inline size_t RecursiveDynamicUsage(const CMutableTransaction& tx) {
45 for (std::vector<CTxIn>::const_iterator it = tx.vin.begin(); it != tx.vin.end(); it++) {
46 mem += RecursiveDynamicUsage(*it);
47 }
48 for (std::vector<CTxOut>::const_iterator it = tx.vout.begin(); it != tx.vout.end(); it++) {
49 mem += RecursiveDynamicUsage(*it);
50 }
51 return mem;
52}
53
54static inline size_t RecursiveDynamicUsage(const CBlock& block) {
55 size_t mem = memusage::DynamicUsage(block.vtx);
56 for (const auto& tx : block.vtx) {
58 }
59 return mem;
60}
61
62static inline size_t RecursiveDynamicUsage(const CBlockLocator& locator) {
63 return memusage::DynamicUsage(locator.vHave);
64}
65
66template<typename X>
67static inline size_t RecursiveDynamicUsage(const std::shared_ptr<X>& p) {
68 return p ? memusage::DynamicUsage(p) + RecursiveDynamicUsage(*p) : 0;
69}
70
71#endif // BITCOIN_CORE_MEMUSAGE_H
Definition: block.h:69
std::vector< CTransactionRef > vtx
Definition: block.h:72
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:29
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:415
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:296
const std::vector< CTxOut > vout
Definition: transaction.h:307
const std::vector< CTxIn > vin
Definition: transaction.h:306
An input of a transaction.
Definition: transaction.h:67
CScript scriptSig
Definition: transaction.h:70
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:72
COutPoint prevout
Definition: transaction.h:69
An output of a transaction.
Definition: transaction.h:150
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
Definition: memusage.h:31
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:124
std::vector< uint256 > vHave
Definition: block.h:134
A mutable version of CTransaction.
Definition: transaction.h:378
std::vector< CTxOut > vout
Definition: transaction.h:380
std::vector< CTxIn > vin
Definition: transaction.h:379
std::vector< std::vector< unsigned char > > stack
Definition: script.h:588