aboutsummaryrefslogtreecommitdiff
path: root/src/coins.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-05-15 13:39:31 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-05-15 13:43:02 +0200
commit6fb90d898355dc1cec7b2bfb4f38d8503886bafb (patch)
treed9a0c463470611561ce8ad13ec5aa401bf4c2114 /src/coins.h
parent63e7016566f382ff59fe724d09d556022c897222 (diff)
parent86a5f4b54ebf5f3251f4c172cf9a5041ae43c082 (diff)
downloadbitcoin-6fb90d898355dc1cec7b2bfb4f38d8503886bafb.tar.xz
Merge pull request #6102
86a5f4b Relocate calls to CheckDiskSpace (Alex Morcos) 67708ac Write block index more frequently than cache flushes (Pieter Wuille) b3ed423 Cache tweak and logging improvements (Pieter Wuille) fc684ad Use accurate memory for flushing decisions (Pieter Wuille) 046392d Keep track of memory usage in CCoinsViewCache (Pieter Wuille) 540629c Add memusage.h (Pieter Wuille)
Diffstat (limited to 'src/coins.h')
-rw-r--r--src/coins.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/coins.h b/src/coins.h
index fe2eaa08e5..a4671645df 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -7,6 +7,7 @@
#define BITCOIN_COINS_H
#include "compressor.h"
+#include "memusage.h"
#include "serialize.h"
#include "uint256.h"
@@ -252,6 +253,15 @@ public:
return false;
return true;
}
+
+ size_t DynamicMemoryUsage() const {
+ size_t ret = memusage::DynamicUsage(vout);
+ BOOST_FOREACH(const CTxOut &out, vout) {
+ const std::vector<unsigned char> *script = &out.scriptPubKey;
+ ret += memusage::DynamicUsage(*script);
+ }
+ return ret;
+ }
};
class CCoinsKeyHasher
@@ -356,7 +366,8 @@ class CCoinsModifier
private:
CCoinsViewCache& cache;
CCoinsMap::iterator it;
- CCoinsModifier(CCoinsViewCache& cache_, CCoinsMap::iterator it_);
+ size_t cachedCoinUsage; // Cached memory usage of the CCoins object before modification
+ CCoinsModifier(CCoinsViewCache& cache_, CCoinsMap::iterator it_, size_t usage);
public:
CCoins* operator->() { return &it->second.coins; }
@@ -372,6 +383,7 @@ protected:
/* Whether this cache has an active modifier. */
bool hasModifier;
+
/**
* Make mutable so that we can "fill the cache" even from Get-methods
* declared as "const".
@@ -379,6 +391,9 @@ protected:
mutable uint256 hashBlock;
mutable CCoinsMap cacheCoins;
+ /* Cached dynamic memory usage for the inner CCoins objects. */
+ mutable size_t cachedCoinsUsage;
+
public:
CCoinsViewCache(CCoinsView *baseIn);
~CCoinsViewCache();
@@ -414,6 +429,9 @@ public:
//! Calculate the size of the cache (in number of transactions)
unsigned int GetCacheSize() const;
+ //! Calculate the size of the cache (in bytes)
+ size_t DynamicMemoryUsage() const;
+
/**
* Amount of bitcoins coming in to a transaction
* Note that lightweight clients may not know anything besides the hash of previous transactions,