3 ms·
Because unique_ptr (and shared_ptr) have non-trivial destructors, due to the Itanium C++ ABI they cannot be passed in registers. See https://stackoverflow.com/
by ndesaulniers 4y ago
Because unique_ptr (and shared_ptr) have non-trivial destructors, due to the Itanium C++ ABI they cannot be passed in registers.
See https://stackoverflow.com/a/58340952 https://stackoverflow.com/a/58340952.
Everything in C++ is zero cost, until it's not...oops!
- chrisseaton 4y ago> due to the Itanium C++ ABI But you don’t have to follow anyone’s ABI inside your own code do you?
- olliej 4y agoIn C++ and other system languages you generally do. In general they assume object at a time compiler (in the compiler sense, not types), and different objects may come from other compilers, instances, or even languages. So they use the standard ABI. For an internal function they don’t have to use the standard ABI as by definition all users of that function are from within the current object. In such cases compilers can optimize the calling convention. I recall that msvc at least did this - but in those cases they’re free to change anything - they can in-line and not include the function at all in the resultant object. That’s why you often see “static inline”
- vlovich123 4y agoI believe compilers may not stick to strict ABI in a LTO build since there’s no real object files and the compiler has a full view of the build. I don’t know if clang/GCC do things to take advantage of that but I feel like they would be doing that for easy perf wins.