特征实例包含另一个持有固定大小特征对象的实例

特征实例包含另一个持有固定大小特征对象的实例

本文介绍了特征实例包含另一个持有固定大小特征对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读了本征页面。后者指出以下内容:

However it's not clear to me whether we should also use the EIGEN_MAKE_ALIGNED_OPERATOR_NEW macro for class instances that hold other class instances which in turn hold the fixed-size containers?

For example, in class A of the followin snippet, is the EIGEN_MAKE_ALIGNED_OPERATOR_NEW needed?

#include <Eigen/Core>

class B
{
public:
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
  Eigen::Vector2d v;
};

class A
{
public:
  B b;
};


int main(int argc, char *argv[])
{
  B* b = new B(); // this should have no alignement problems as we use EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  A* a = new A(); // how about this one?

  return 0;
}
解决方案

In your case it is needed in both A and B. If A would inherit from B it would also inherit the new operator (thus making it not necessary to write again). Also, if B itself would never be allocated directly, but just as part of A, you would need the EIGEN_MAKE_ALIGNED_OPERATOR_NEW only in A.

Also, if you compile for a x86_64 architecture your program will also very likely work, since most compilers will always 16byte-align the result of new, on the other hand, just adding EIGEN_MAKE_ALIGNED_OPERATOR_NEW everywhere will barely have a performance impact (unless you excessively (de-)allocate objects).

这篇关于特征实例包含另一个持有固定大小特征对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 17:10