3 ms·
https://gcc.godbolt.org/z/TMYso5 https://gcc.godbolt.org/z/TMYso5 If you pass a unique_ptr it has to have redirection through a pointer, so it isn't quite zero
by mhh__ 6y ago
https://gcc.godbolt.org/z/TMYso5 https://gcc.godbolt.org/z/TMYso5
If you pass a unique_ptr it has to have redirection through a pointer, so it isn't quite zero cost.
However, since the entire point of using a smart pointer is to control the ownership I'm not that bothered.
- tempsolution 6y agoWhat are you talking about? unique_ptr contains a pointer, that's it. Yes, to represent a pointer you have to contain a point. Passing it on or not makes zero difference and using a website that return unoptimized C++, is not a good place to gather intel. unique_ptr is zero cost, unless you use it across library boundaries without LTO.
- shultays 6y agoZero cost compared to a raw pointer. You are comparing apple and oranges if you compare it to a regular variable. It has a null check on destructor (and a delete of course), which is good enough for "zero cost" to me
- shultays 6y agoHmm, now i thinked about this one but perhaps it is fair to compare unique_ptr to regular variables as well. I guess it is more complicated than i thought, but i think it is fair to compare them pointers too. Because most of the time you will probably need to store it as a pointer