The destruction of memory from the guts of Eigen impolite, not least because you do not know how it was isolated, or what else belongs to the Matrix.
However, there is a Map template that allows you to wrap an uncured buffer in a type similar to a matrix.
This type is not an actual native matrix, so your own custom functions may not work with it, but it should work with Eigen functions.
In this case, you already have the data.
using matrix_type = Matrix<float, Dynamic, Dynamic, RowMajor>; using mapped_matrix_type = Map<matrix_type>;
Now we create a buffer, wrap it in mapped_matrix_type and assign:
auto raw = std::make_unique<float[]>(m1.rows()*m2.cols());
raw bob data is in a raw , a unique_ptr owned buffer (which can release() if you need to make it completely unoccupied).
Any raw storage mechanism ( vector , raw new , everything else) can replace the raw location.
Code not verified.
source share