Bitcoin ABC  0.24.7
P2P Digital Currency
core_memusage.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2016 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 
8 #include <memusage.h>
9 #include <primitives/block.h>
10 #include <primitives/transaction.h>
11 
12 static inline size_t RecursiveDynamicUsage(const CScript &script) {
13  return memusage::DynamicUsage(*static_cast<const CScriptBase *>(&script));
14 }
15 
16 static inline size_t RecursiveDynamicUsage(const COutPoint &out) {
17  return 0;
18 }
19 
20 static inline size_t RecursiveDynamicUsage(const CTxIn &in) {
21  return RecursiveDynamicUsage(in.scriptSig) +
23 }
24 
25 static inline size_t RecursiveDynamicUsage(const CTxOut &out) {
27 }
28 
29 static inline size_t RecursiveDynamicUsage(const CTransaction &tx) {
30  size_t mem =
32  for (std::vector<CTxIn>::const_iterator it = tx.vin.begin();
33  it != tx.vin.end(); it++) {
34  mem += RecursiveDynamicUsage(*it);
35  }
36  for (std::vector<CTxOut>::const_iterator it = tx.vout.begin();
37  it != tx.vout.end(); it++) {
38  mem += RecursiveDynamicUsage(*it);
39  }
40  return mem;
41 }
42 
43 static inline size_t RecursiveDynamicUsage(const CMutableTransaction &tx) {
44  size_t mem =
46  for (std::vector<CTxIn>::const_iterator it = tx.vin.begin();
47  it != tx.vin.end(); it++) {
48  mem += RecursiveDynamicUsage(*it);
49  }
50  for (std::vector<CTxOut>::const_iterator it = tx.vout.begin();
51  it != tx.vout.end(); it++) {
52  mem += RecursiveDynamicUsage(*it);
53  }
54  return mem;
55 }
56 
57 template <typename X>
58 static inline size_t RecursiveDynamicUsage(const std::shared_ptr<X> &p) {
59  return p ? memusage::DynamicUsage(p) + RecursiveDynamicUsage(*p) : 0;
60 }
61 
62 #endif // BITCOIN_CORE_MEMUSAGE_H
CTxIn
An input of a transaction.
Definition: transaction.h:61
block.h
CTransaction::vin
const std::vector< CTxIn > vin
Definition: transaction.h:210
transaction.h
memusage::DynamicUsage
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
Definition: memusage.h:26
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
RecursiveDynamicUsage
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
CTxOut
An output of a transaction.
Definition: transaction.h:130
CTransaction::vout
const std::vector< CTxOut > vout
Definition: transaction.h:211
CTxOut::scriptPubKey
CScript scriptPubKey
Definition: transaction.h:133
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
prevector
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:38
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:281
memusage.h
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:63
CTxIn::scriptSig
CScript scriptSig
Definition: transaction.h:64
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:280
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:278