3 /** \eigenManualPage TopicPassingByValue Passing Eigen objects by value to functions
5 Passing objects by value is almost always a very bad idea in C++, as this means useless copies, and one should pass them by reference instead.
7 With Eigen, this is even more important: passing \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen objects" by value is not only inefficient, it can be illegal or make your program crash! And the reason is that these Eigen objects have alignment modifiers that aren't respected when they are passed by value.
9 So for example, a function like this, where v is passed by value:
12 void my_function(Eigen::Vector2d v);
15 needs to be rewritten as follows, passing v by reference:
18 void my_function(const Eigen::Vector2d& v);
21 Likewise if you have a class having a Eigen object as member:
28 void my_function(Foo v);
31 This function also needs to be rewritten like this:
33 void my_function(const Foo& v);
36 Note that on the other hand, there is no problem with functions that return objects by value.