On a 64-bit system, const&
is 8 bytes. For values and objects smaller than 8 bytes, it makes sense to pass by value rather than reference. Even an 8 byte object is cheaper to copy than to pass the reference, then access the object.
At what threshold should you prefer a const reference over a const value?
For values and objects smaller than 8 bytes, it makes sense to pass by value rather than reference. Even an 8 byte object is cheaper to copy than to pass the reference, then access the object.
References are not guaranteed to be implemented as pointers. In fact as per §8.3.2/4:
It is unspecified whether or not a reference requires storage
At what threshold should you prefer a const reference over a const value?
The situation is pretty simple:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With