title: Transitive effect of Eigen EIGEN_MAKE_ALIGNED_OPERATOR_NEW?
body: <p>Recently, I was made aware of the potential issues of <a href="https://eigen.tuxfamily.org/dox/group__DenseMatrixManipulation__Alignement.html" rel="noreferrer">memory alignment</a> for <a href="https://eigen.tuxfamily.org/dox/group__TopicFixedSizeVectorizable.html" rel="noreferrer">Fixed-size vectorizable Eigen objects</a>.</p>
  <p>The correct code as stated in <a href="https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html" rel="noreferrer">the doc</a>:</p>
  <pre><code>class Foo
  {
    ...
    Eigen::Vector2d v;
    ...
  public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  };
   
  ...
   
  Foo *foo = new Foo;
  </code></pre>
  <p>I would like to know if this code is ok or not?</p>
  <pre><code>class Foo2
  {
    ...
    Foo foo;
    ...
  };
   
  ...
   
  Foo2 *foo = new Foo2; //?
  </code></pre>
  <p>Or should <code>EIGEN_MAKE_ALIGNED_OPERATOR_NEW</code> be again added in the <code>Foo2</code> class?
  This is what is suggested <a href="https://github.com/cartographer-project/cartographer/issues/34#issuecomment-252253736" rel="noreferrer">here</a> I think:</p>
  <blockquote>
  <p>If we were to add EIGEN_MAKE_ALIGNED_OPERATOR_NEW this would only solve the problem for the Cartographer library itself. Users of the library would also have to add EIGEN_MAKE_ALIGNED_OPERATOR_NEW to classes containing vectorized Cartographer classes. This sounds like a maintenance nightmare.</p>
  </blockquote>
  <p>I have no experience with new operator overloading. I think the question is more general and would somehow be related to how new operator works in C++. For instance is the overloaded new operator in <code>Foo</code> be called by the default new operator in <code>Foo2</code>? What about inheritance? If <code>Foo2</code> inherits from <code>Foo</code>, should we put also <code>EIGEN_MAKE_ALIGNED_OPERATOR_NEW</code> in <code>Foo2</code>?</p>
  <hr />
  <p>Since I was only aware of this topic recently, I did many research and found the following:</p>
  <ul>
  <li>default alignment on x86-64 is 16 bytes, so it is fine to not have <code>EIGEN_MAKE_ALIGNED_OPERATOR_NEW</code> (if only SSE is enabled)</li>
  <li>unless your code is compiled for more recent SIMD sets (e.g. AVX2 with <code>-march=native</code> to have all the optimizations on a local computer), <code>EIGEN_MAKE_ALIGNED_OPERATOR_NEW</code> is now needed</li>
  <li>what about the other architecture? For instance for ARM, any issue if we don't declare <code>EIGEN_MAKE_ALIGNED_OPERATOR_NEW</code> and NEON is enabled?</li>
  <li>I found suggestion to use <code>template &lt;typename Scalar&gt; using Isometry3 = Eigen::Transform&lt;Scalar, 3, Eigen::Isometry | Eigen::DontAlign&gt;</code> instead of <code>Isometry</code></li>
  <li>still need to think on how to be able to easily use Eigen type (e.g. <code>Isometry3d</code>) in the code without the alignment issue. So add a new type <code>MyIsometry3d</code> that inherits from <code>Eigen::Transform&lt;double, 3, Eigen::Isometry | Eigen::DontAlign&gt;</code> for instance?</li>
  </ul>
  <p>More generally, I would like to &quot;disable alignment&quot; (or vectorization) in fixed-size Eigen type:</p>
  <ul>
  <li>I would like to keep the syntax, for instance keeping <code>Isometry3d</code> in the code</li>
  <li>and not be bothered with alignment issue when using <code>Isometry3d</code> in a class or when using <code>std::vector&lt;Isometry3d&gt;</code></li>
  <li>something to tell Eigen to always use unaligned load/store (e.g. <code>_loadu_</code>/<code>_storeu_</code> for x86-64 intrinsics, what about the other architecture, is there an equivalent?) for all fixed-size Eigen type?</li>
  <li>else just disable vectorization for fixed-size Eigen type since I believe penalty should be (almost) null between using vectorized instructions and just C++ code for these types</li>
  <li>so I guess the solution is to use <code>#define EIGEN_UNALIGNED_VECTORIZE 0</code>, is it correct? So I have to put this <code>#define</code> everywhere before any <code>Eigen/Dense</code> include?</li>
  <li>I don't want to replace everywhere with something like <code>Matrix&lt;double,2,2,DontAlign&gt;</code> or a new class</li>
  </ul>
  <p>Finally, looking at <a href="https://eigen.tuxfamily.org/dox/group__TopicFixedSizeVectorizable.html" rel="noreferrer">Fixed-size vectorizable Eigen objects</a> page, I think some types are missing. For the types I am using:</p>
  <ul>
  <li><code>Eigen::Isometry3d</code>, <code>Eigen::Isometry3f</code>?</li>
  <li><code>Eigen::AngleAxisd</code>, <code>Eigen::AngleAxisf</code>?</li>
  </ul>