page =
url = https://quuxplusone.github.io/blog
arthur o'dwyer – stuff mostly about c++
library-design parameter-only-types
Several readers have responded to my recent post “Three reasons to pass std::string_view by value” (2021-11-09), pointing out that (while everything I said is true of the Itanium x86-64 ABI used on Linux and Mac) unfortunately Microsoft’s x86-64 ABI does not pass
in registers, but instead passes it by “hidden pointer,” so that at the machine level, you get basically the same codegen as if you had been passing by reference all along. Except that actually you’re passing a copy by reference, so you get one extra 16-byte copy in addition to all the other stack traffic MSVC is doing.
This is a big problem baked into Microsoft’s x86-64 ABI, and nerfs a lot of the performance benefits mentioned in my post. However, my advice remains the same: Even if your primary platform today is Windows, you should habitually pass
by value!