You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. namespace StormEigen {
  2. /** \eigenManualPage TopicPassingByValue Passing Eigen objects by value to functions
  3. 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.
  4. 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.
  5. So for example, a function like this, where v is passed by value:
  6. \code
  7. void my_function(StormEigen::Vector2d v);
  8. \endcode
  9. needs to be rewritten as follows, passing v by reference:
  10. \code
  11. void my_function(const StormEigen::Vector2d& v);
  12. \endcode
  13. Likewise if you have a class having a Eigen object as member:
  14. \code
  15. struct Foo
  16. {
  17. StormEigen::Vector2d v;
  18. };
  19. void my_function(Foo v);
  20. \endcode
  21. This function also needs to be rewritten like this:
  22. \code
  23. void my_function(const Foo& v);
  24. \endcode
  25. Note that on the other hand, there is no problem with functions that return objects by value.
  26. */
  27. }