1 // Copyright (c) 2015 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.
5 #ifndef BITCOIN_CORE_MEMUSAGE_H
6 #define BITCOIN_CORE_MEMUSAGE_H
8 #include "primitives/transaction.h"
9 #include "primitives/block.h"
12 static inline size_t RecursiveDynamicUsage(const CScript
& script
) {
13 return memusage::DynamicUsage(*static_cast<const std::vector
<unsigned char>*>(&script
));
16 static inline size_t RecursiveDynamicUsage(const COutPoint
& out
) {
20 static inline size_t RecursiveDynamicUsage(const CTxIn
& in
) {
21 return RecursiveDynamicUsage(in
.scriptSig
) + RecursiveDynamicUsage(in
.prevout
);
24 static inline size_t RecursiveDynamicUsage(const CTxOut
& out
) {
25 return RecursiveDynamicUsage(out
.scriptPubKey
);
28 static inline size_t RecursiveDynamicUsage(const CTransaction
& tx
) {
29 size_t mem
= memusage::DynamicUsage(tx
.vin
) + memusage::DynamicUsage(tx
.vout
);
30 for (std::vector
<CTxIn
>::const_iterator it
= tx
.vin
.begin(); it
!= tx
.vin
.end(); it
++) {
31 mem
+= RecursiveDynamicUsage(*it
);
33 for (std::vector
<CTxOut
>::const_iterator it
= tx
.vout
.begin(); it
!= tx
.vout
.end(); it
++) {
34 mem
+= RecursiveDynamicUsage(*it
);
39 static inline size_t RecursiveDynamicUsage(const CMutableTransaction
& tx
) {
40 size_t mem
= memusage::DynamicUsage(tx
.vin
) + memusage::DynamicUsage(tx
.vout
);
41 for (std::vector
<CTxIn
>::const_iterator it
= tx
.vin
.begin(); it
!= tx
.vin
.end(); it
++) {
42 mem
+= RecursiveDynamicUsage(*it
);
44 for (std::vector
<CTxOut
>::const_iterator it
= tx
.vout
.begin(); it
!= tx
.vout
.end(); it
++) {
45 mem
+= RecursiveDynamicUsage(*it
);
50 static inline size_t RecursiveDynamicUsage(const CBlock
& block
) {
51 size_t mem
= memusage::DynamicUsage(block
.vtx
) + memusage::DynamicUsage(block
.vMerkleTree
);
52 for (std::vector
<CTransaction
>::const_iterator it
= block
.vtx
.begin(); it
!= block
.vtx
.end(); it
++) {
53 mem
+= RecursiveDynamicUsage(*it
);
58 static inline size_t RecursiveDynamicUsage(const CBlockLocator
& locator
) {
59 return memusage::DynamicUsage(locator
.vHave
);
62 #endif // BITCOIN_CORE_MEMUSAGE_H