In the new "C++ Programming Language" book(and probably in previous versions), Bjarne Stroustrup recommends:
- Use pass-by-value for small objects
- Use pass-by-const-reference to pass large values that you don't need to modify.
- ...
Is there a common accepted definition for small objects when it comes to arguments passing? For example it's obvious that any object smaller than the address size is a small object, but what about the objects that have 2, 3, 4 times the size of an address? Are they considered small and should be passed by value?
As a sample code to work on:
struct Vector {float x, y, z;};
Should I prefer:
void do_something_with_vector(Vector v){...}
or:
void do_something_with_vector(const Vector& v){...}