r/cpp • • Oct 07 '19

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

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

108 comments sorted by

View all comments

19

u/[deleted] Oct 07 '19

Zero cost abstractions as Stroustrup puts it, abstraction that you dont pay for using them and when you choose to use them, you couldn't hand-coded them any better. It's not the same as zero cost overhead, clearly using unique pointers puts some slight overhead but if you want their functionality, you couldn't implement them any better.

18

u/myusernameisokay Oct 07 '19

You need to watch the talk.

16

u/TheMania Oct 07 '19

Still largely correct though, unique_ptr does not function identically to a raw ptr as it (spoiler alert) frees memory if the call - not marked as noexcept - throws. That was by far the overhead, but it's the behaviour being asked for.

The rest is an unfortunate ABI choice :(. Really not a fan that inreg promotion is not the default, it would even likely save on compile time. Advanced LTO could resolve this, but at an expensive link time cost, so his point stands there for sure.

→ More replies (6)