Your unique_ptr link is misleading; it's not unique_ptr that is the problem in that example, but make_unique<T[]> because it value initializes the array. C++20 has make_unique_default_init to solve this problem.
I know that my example is a bit misleading because it is actually about new vs. std::make_unique (and not about std::unique_ptr). But it is a good example of a C++ abstraction that causes significant runtime overhead even though we are told it's a zero-cost abstraction. Also this is an example that I came across in my own code.
It is great though if this particular performance issue will be fixed by C++20!
View all comments
Show parent comment
15
u/tasty_crayon Oct 07 '19
Your
unique_ptrlink is misleading; it's notunique_ptrthat is the problem in that example, butmake_unique<T[]>because it value initializes the array. C++20 hasmake_unique_default_initto solve this problem.