Re: [eigen] Passing Eigen::Map types to functions that take Eigen types

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hello Martin,

Your do_work_ptr definition should look like this:

void do_work_ptr (double* ptr, int rows, int cols) {
  Eigen::Map<Eigen::MatrixXd> mat_data(ptr, rows, cols);
  do_work (mat_data);
}

Your original version was instructing Eigen to first create a map around the pointer, and then copy the elements to a new Matrix. The above version only creates the map.

However, I wonder why you are not using Eigen for the data storage inside your library? The do_work_ptr approach you have described is prone to memory leaks if you are not careful. Eigen has a .data() method that will return a pointer to the underlying array if you ever need it.

Toby



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/