I'm trying to take ownership of the memory backing an Eigen::Matrix
without copying the memory. The data()
method retains ownership. The only way I've figured out how to do this is by swapping the mapped array:
Matrix<float, Dynamic, Dynamic, RowMajor> mat = m1 * m2;
// want ownership of mat's float*
float* data = mat.data(); // get the pointer
new (&mat) Eigen::Map<Matrix3f>(NULL); // swap the mapped array with anything else
// do something with data
It doesn't look like this causes a copy under the hood, but I'm not positive. I'm also not sure that this is safe.
float *
. – Freemasonryfloat*
isn't a full API. Afloat*
allocated by what means, and freed by what means? In C/C++ you must always keep track of who owns what, and how to dispose of leftover data. If you fail, you end up with leaks and corruption and mess. – Blackenfloat*
and takes ownership of its memory, taking care of freeing it. – Freemasonry