aboutsummaryrefslogtreecommitdiff
path: root/src/memusage.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-06-08 14:01:05 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-06-08 14:01:18 +0200
commita7c41f2de03c315394c0560f369544e24a3e5586 (patch)
tree919733dfaa3aaaadbf9f944a72c57557f3268275 /src/memusage.h
parent761cddb69029cbef1fc62267aeb2e4c17c6ed34d (diff)
parent288d85ddf2e0a0c9d25a23db56052883170466d0 (diff)
Merge #8126: std::shared_ptr based CTransaction storage in mempool
288d85d Get rid of CTxMempool::lookup() entirely (Pieter Wuille) c2a4724 Optimization: use usec in expiration and reuse nNow (Pieter Wuille) e9b4780 Optimization: don't check the mempool at all if no mempool req ever (Pieter Wuille) dbfb426 Optimize the relay map to use shared_ptr's (Pieter Wuille) 8d39d7a Switch CTransaction storage in mempool to std::shared_ptr (Pieter Wuille) 1b9e6d3 Add support for unique_ptr and shared_ptr to memusage (Pieter Wuille)
Diffstat (limited to 'src/memusage.h')
-rw-r--r--src/memusage.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/memusage.h b/src/memusage.h
index 9c98e5c2cf..3810bfad07 100644
--- a/src/memusage.h
+++ b/src/memusage.h
@@ -72,6 +72,15 @@ private:
X x;
};
+struct stl_shared_counter
+{
+ /* Various platforms use different sized counters here.
+ * Conservatively assume that they won't be larger than size_t. */
+ void* class_type;
+ size_t use_count;
+ size_t weak_count;
+};
+
template<typename X>
static inline size_t DynamicUsage(const std::vector<X>& v)
{
@@ -122,6 +131,21 @@ static inline size_t IncrementalDynamicUsage(const indirectmap<X, Y>& m)
return MallocUsage(sizeof(stl_tree_node<std::pair<const X*, Y> >));
}
+template<typename X>
+static inline size_t DynamicUsage(const std::unique_ptr<X>& p)
+{
+ return p ? MallocUsage(sizeof(X)) : 0;
+}
+
+template<typename X>
+static inline size_t DynamicUsage(const std::shared_ptr<X>& p)
+{
+ // A shared_ptr can either use a single continuous memory block for both
+ // the counter and the storage (when using std::make_shared), or separate.
+ // We can't observe the difference, however, so assume the worst.
+ return p ? MallocUsage(sizeof(X)) + MallocUsage(sizeof(stl_shared_counter)) : 0;
+}
+
// Boost data structures
template<typename X>