diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2016-05-30 16:50:14 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2016-06-05 00:31:35 +0200 |
commit | 1b9e6d3c1a0f0e7eeff5ddb2e0386911fe9ab2b6 (patch) | |
tree | 78d4478c7c7cecf0c94e2975b719bef5ff75bb70 /src | |
parent | d46b8b50fc3e725df75378db2d81aa48f9a1bd74 (diff) |
Add support for unique_ptr and shared_ptr to memusage
Diffstat (limited to 'src')
-rw-r--r-- | src/memusage.h | 24 |
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> |