Bitcoin ABC 0.30.5
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>
11
12static inline size_t RecursiveDynamicUsage(const CScript &script) {
13 return memusage::DynamicUsage(*static_cast<const CScriptBase *>(&script));
14}
15
16static inline size_t RecursiveDynamicUsage(const COutPoint &out) {
17 return 0;
18}
19
20static inline size_t RecursiveDynamicUsage(const CTxIn &in) {
21 return RecursiveDynamicUsage(in.scriptSig) +
22 RecursiveDynamicUsage(in.prevout);
23}
24
25static inline size_t RecursiveDynamicUsage(const CTxOut &out) {
27}
28
29static 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
43static 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
57template <typename X>
58static 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
A mutable version of CTransaction.
Definition: transaction.h:274
std::vector< CTxOut > vout
Definition: transaction.h:277
std::vector< CTxIn > vin
Definition: transaction.h:276
An output of a transaction.
Definition: transaction.h:128
CScript scriptPubKey
Definition: transaction.h:131
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:38
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:27