aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/PassingByValue.dox
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-12 14:41:12 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-01-12 14:41:12 +0000
commit294f5f16dd6286a0ac14c2d8194db3a95fdfb301 (patch)
tree24c3232eec1f29fd1b184d0ee8336e6443c453fa /doc/PassingByValue.dox
parentf86818b5a6a1e47f95e42c4387c0cda5671b532e (diff)
muuuch improved documentation for the unaligned array assert.
also split into several pages for better reusability (more generally useful than just for this assert)
Diffstat (limited to 'doc/PassingByValue.dox')
-rw-r--r--doc/PassingByValue.dox40
1 files changed, 40 insertions, 0 deletions
diff --git a/doc/PassingByValue.dox b/doc/PassingByValue.dox
new file mode 100644
index 000000000..6eaf9ccb9
--- /dev/null
+++ b/doc/PassingByValue.dox
@@ -0,0 +1,40 @@
+namespace Eigen {
+
+/** \page PassingByValue Passing Eigen objects by value to functions
+
+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.
+
+With Eigen, this is even more important: passing \ref FixedSizeVectorizable "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.
+
+So for example, a function like this, where v is passed by value:
+
+\code
+void my_function(Eigen::Vector2d v);
+\endcode
+
+needs to be rewritten as follows, passing v by reference:
+
+\code
+void my_function(const Eigen::Vector2d& v);
+\endcode
+
+Likewise if you have a class having a Eigen object as member:
+
+\code
+struct Foo
+{
+ Eigen::Vector2d v;
+};
+void my_function(Foo v);
+\endcode
+
+This function also needs to be rewritten like this:
+\code
+void my_function(const Foo& v);
+\endcode
+
+Note that on the other hand, there is no problem with functions that return objects by value.
+
+*/
+
+}