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