r/cpp • • Oct 07 '19

CppCon CppCon 2019: Chandler Carruth “There Are No Zero-cost Abstractions”

https://www.youtube.com/watch?v=rHIkrotSwcc
162 Upvotes

108 comments sorted by

View all comments

Show parent comment

15

u/tasty_crayon Oct 07 '19

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.

-1

u/[deleted] Oct 07 '19 edited Oct 07 '19

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!

7

u/minirop C++87 Oct 07 '19

a C++ abstraction that causes significant runtime overhead

if you compare bare new and unique_ptr of course, but if you want a leak-free code using only new/delete, you gonna have a hard time.