File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,15 @@ struct stl_tree_node
8080 X x;
8181};
8282
83+ struct stl_shared_counter
84+ {
85+ /* Various platforms use different sized counters here.
86+ * Conservatively assume that they won't be larger than size_t. */
87+ void * class_type;
88+ size_t use_count;
89+ size_t weak_count;
90+ };
91+
8392template <typename X>
8493static inline size_t DynamicUsage (const std::vector<X>& v)
8594{
@@ -158,6 +167,21 @@ static inline size_t RecursiveDynamicUsage(const std::pair<X, Y>& v)
158167 return RecursiveDynamicUsage (v.first ) + RecursiveDynamicUsage (v.second );
159168}
160169
170+ template <typename X>
171+ static inline size_t DynamicUsage (const std::unique_ptr<X>& p)
172+ {
173+ return p ? MallocUsage (sizeof (X)) : 0 ;
174+ }
175+
176+ template <typename X>
177+ static inline size_t DynamicUsage (const std::shared_ptr<X>& p)
178+ {
179+ // A shared_ptr can either use a single continuous memory block for both
180+ // the counter and the storage (when using std::make_shared), or separate.
181+ // We can't observe the difference, however, so assume the worst.
182+ return p ? MallocUsage (sizeof (X)) + MallocUsage (sizeof (stl_shared_counter)) : 0 ;
183+ }
184+
161185// Boost data structures
162186
163187template <typename X>
You can’t perform that action at this time.
0 commit comments