c++ - Why is std::tr1::shared_ptr<>.reset() so expensive? -
Some of the codes that are heavily shared_ptrs, I found that the reset () was surprisingly Costly
For example:
structure testing {int i; Test () {it-> I = 0; } Test (int i) {it-> I = i; }}; ... auto t = make_shared & lt; Test & gt; (1); ... t. Reset (some pointertoast object);
Detect reset () in the previous row (under VC ++ 2010), I found out that it creates a new reference-count object.
Is there an inexpensive method that reuses existing regga-count and does not bother the heap?
In the general case, you can not reuse existing ref calculations because other if You can use
s or somePointerToATestObject
for make_shared ()
command_property
s or weak_peter
s Can be used. , Then the implementation may be use a heap allocation for both the referee calculation and the object. This will save you one of the heap allocation.
Comments
Post a Comment