C++11 在Eigen中识别临时对象创建 由于在许多地方指出了特征C++库的文档,为了在计算时间上获得最大的性能,我们需要尽量避免临时对象。在我的应用程序中,我处理动态大小矩阵。我想知道在我的计算中临时矩阵的创建。是否有确定临时矩阵创建的一般方法

C++11 在Eigen中识别临时对象创建 由于在许多地方指出了特征C++库的文档,为了在计算时间上获得最大的性能,我们需要尽量避免临时对象。在我的应用程序中,我处理动态大小矩阵。我想知道在我的计算中临时矩阵的创建。是否有确定临时矩阵创建的一般方法,c++11,eigen3,C++11,Eigen3,比如说, Eigen::MatrixXf B, C, D; ....some initialization for B, C, D Eigen::MatrixXf A = B*C+D; 如何在实现此操作时检查创建了多少临时矩阵?您可以使用插件机制来检查。在包含任何特征头之前,请定义以下内容: static long int nb_temporaries; static long int nb_temporaries_on_assert = -1; inline void on_temporar

比如说,

Eigen::MatrixXf B, C, D;
....some initialization for B, C, D
Eigen::MatrixXf A = B*C+D;

如何在实现此操作时检查创建了多少临时矩阵?

您可以使用插件机制来检查。在包含任何特征头之前,请定义以下内容:

static long int nb_temporaries;
static long int nb_temporaries_on_assert = -1;
inline void on_temporary_creation(long int size) {
  // here's a great place to set a breakpoint when debugging failures in this test!
  if(size!=0) nb_temporaries++;
  if(nb_temporaries_on_assert>0) assert(nb_temporaries<nb_temporaries_on_assert);
}

#define EIGEN_DENSE_STORAGE_CTOR_PLUGIN { on_temporary_creation(size); }
static long int nb_temporaries;
静态long int nb_temporaries_on_assert=-1;
临时创建时的内联无效(长整型大小){
//这里是调试此测试中失败时设置断点的好地方!
如果(大小!=0)nb_临时值++;
如果(nb_临时变量上的nb_断言>0)断言(nb_临时变量