使用 Eigen::Map 进行堆管理:是用户还是 Eigen::Matrix 负责?

Heap management with Eigen::Map : Is that user or Eigen::Matrix responsability?

当 Eigen::Map 与堆内存段一起创建 MAtrix 时,谁来处理堆取消分配?

当调用Eigen::Map构建矩阵时,我找不到任何关于内部矩阵数据内存段管理的信息。 这是我浏览的文档:https://eigen.tuxfamily.org/dox/group__TutorialMapClass.html

当我在下面的代码中完成矩阵 "mf" 后,我是否应该处理内存段删除?

  int rows(3),  cols (3);
  scomplex *m1Data = new scomplex[rows*cols];
  for (int i = 0; i<cols*rows; i++)
  {  
    m1Data[i] = scomplex( i, 2*i);
  }

  Map<MatrixXcf> mf(m1Data, rows, cols);

现在,如果我在函数 (./Eigen/src/core/util/Memory.h) 中设置断点:

EIGEN_DEVICE_FUNC inline void aligned_free(void *ptr)

主退出时不触发

请问我是否应该考虑当我不再使用我的矩阵时是否必须删除内存段?

干杯

西尔万

Map 对象不占用传递给它的 ownership/responsibility 内存。它可能只是另一个矩阵的视图。在那种情况下,您肯定不会希望它释放内存。

要引用您 linked:

的教程页面

Occasionally you may have a pre-defined array of numbers that you want to use within Eigen as a vector or matrix. While one option is to make a copy of the data, most commonly you probably want to re-use this memory as an Eigen type.

所以,归根结底,你必须删除你分配和使用的内存 Map