Re: [eigen] Passing Eigen::Map types to functions that take Eigen types |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: "eigen@xxxxxxxxxxxxxxxxxxx" <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: [eigen] Passing Eigen::Map types to functions that take Eigen types
- From: "Wood, Tobias" <tobias.wood@xxxxxxxxx>
- Date: Wed, 1 Jul 2015 12:32:19 +0000
- Accept-language: en-GB, en-US
- Authentication-results: lists.tuxfamily.org; dkim=none (message not signed) header.d=none;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
- Thread-index: AQHQs/kOneJblFR3i0GskikLn/kO5Z3GisY6
- Thread-topic: [eigen] Passing Eigen::Map types to functions that take Eigen types
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