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 somePointerToATestObject for make_shared () s or 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

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -