4 ms·
Two minor comments: 1.) Mistake #7 Has been somewhat fixed in the TS by specializing shared_ptr for array types (similar to unique_ptr<type[]> syntax). What th
by sseagull 10y ago
Two minor comments:
1.) Mistake #7 Has been somewhat fixed in the TS by specializing shared_ptr for array types (similar to unique_ptr<type[]> syntax). What they said was true though for C++11.
2.) If the data within a shared_ptr is not owned by any particular object but is otherwise constant, use shared_ptr<const type>. They can be created from a shared_ptr<type> object. This helps with the aliasing problem mentioned in mistake #1
And a slight nitpick on #4 - I imagine the performance of make_shared depends on the library rather than the compiler itself (and I imagine the performance gain is minimal - it is usually used for readability). Also, C++14 add make_unique, which was overlooked in C++11.
- mgraczyk 10y agomake_shared allows the shared pointer to be constructed with its memory and metadata in a contiguous block. This improves cache efficiency and locality and mitigates heap fragmentation. Although make_unique primarily serves to improve readability, make_shared can reduce smart pointer performance overhead dramatically. See http://stackoverflow.com/questions/24779929/what-happens-when-using-make-shared http://stackoverflow.com/questions/24779929/what-happens-whe... You are right in pointing out that the library determines whether using make_shared will improve performance.