aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2011-11-25 13:46:48 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2011-11-25 13:46:48 +0100
commitf56316f7ede6de2d253f7e8174cacfd31599aa6e (patch)
treeae78f0d67fe200db51951dff7df17e3a4e671576 /doc
parent70206ab1e144baa9166f99c92181b9cc9f48d590 (diff)
add two alternative solutions to the problem of fixed size members
Diffstat (limited to 'doc')
-rw-r--r--doc/D09_StructHavingEigenMembers.dox61
1 files changed, 61 insertions, 0 deletions
diff --git a/doc/D09_StructHavingEigenMembers.dox b/doc/D09_StructHavingEigenMembers.dox
index d6a24d951..51789ca9c 100644
--- a/doc/D09_StructHavingEigenMembers.dox
+++ b/doc/D09_StructHavingEigenMembers.dox
@@ -10,6 +10,7 @@ namespace Eigen {
- \ref movetotop
- \ref bugineigen
- \ref conditional
+ - \ref othersolutions
\section summary Executive Summary
@@ -55,6 +56,8 @@ Foo *foo = new Foo;
This macro makes "new Foo" always return an aligned pointer.
+If this approach is too intrusive, see also the \ref othersolutions.
+
\section why Why is this needed?
OK let's say that your code looks like this:
@@ -132,6 +135,64 @@ Foo<4> *foo4 = new Foo<4>; // foo4 is guaranteed to be 128bit-aligned
Foo<3> *foo3 = new Foo<3>; // foo3 has only the system default alignment guarantee
\endcode
+
+\section othersolutions Other solutions
+
+In case putting the EIGEN_MAKE_ALIGNED_OPERATOR_NEW macro everywhere is too intrusive, there exists at least two other solutions.
+
+\subsection othersolutions1 Disabling alignment
+
+The first is to disable alignment requirement for the fixed size members:
+\code
+class Foo
+{
+ ...
+ Eigen::Matrix<double,2,1,Eigen::DontAlign> v;
+ ...
+};
+\endcode
+This has for effect to disable vectorization when using \c v.
+If a function of Foo uses it several times, then it still possible to re-enable vectorization by copying it into an aligned temporary vector:
+\code
+void Foo::bar()
+{
+ Eigen::Vector2d av(v);
+ // use av instead of v
+ ...
+ // if av changed, then do:
+ v = av;
+}
+\endcode
+
+\subsection othersolutions2 Private structure
+
+The second consist in storing the fixed-size objects into a private struct which will be dynamically allocated at the construction time of the main object:
+
+\code
+struct Foo_d
+{
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW
+ Vector2d v;
+ ...
+};
+
+
+struct Foo {
+ Foo() { init_d(); }
+ ~Foo() { delete d; }
+ void bar()
+ {
+ // use d->v instead of v
+ ...
+ }
+private:
+ void init_d() { d = new Foo_d; }
+ Foo_d* d;
+};
+\endcode
+
+The clear advantage here is that the class Foo remains unchanged regarding alignment issues. The drawback is that a heap allocation will be required whatsoever.
+
*/
}