WARNING!!! THE FOLLOWING IS A DRAFT OF PROPOSED FAQ ADDITIONS AND IS STILL UNDERGOING FACT CHECKING!

Memory Management

What actions trigger dynamic memory allocation?

MatrixXf x = MatrixXf::Zero(rows, cols);

Dynamic allocation only when their size is not known at compile time and not even a reasonable upper bound on their size is known at compile time. For example,

Vector4d.segment(x,y).eval() 

does not cause a malloc, since even though the size ‘y’ is not known at compile time, it is known that y<=4. In this case Eigen just reserves space for 4 scalars on the stack.

When does storage get freed by Eigen?

Are there any common/subtle ways to accidentally leak memory in Eigen code?

No, but it is recommended that you use a memory debugger to check your code anyways. Valgrind is recommended on UNIX systems.

Is there a way to check if I’m accidentally triggering dynamic memory allocation in a time critical block of code?

asm("#it begins here!")
y = A*x + b
asm("#it ends here!")

Do I ever need to worry about the storage cost of Matrix headers, and try to re-use them by messing around with pointers?

int rows, cols; Scalar *pointer; In almost all cases where a dynamic sized matrix would be used, this cost is insignificant compared to the size of the contained data.

Array Storage Order (Row-Major vs. Column-Major)

Matrix<float,Dynamic,Dynamic,RowMajor> my_rowmaj_matrix;
#define EIGEN_DEFAULT_TO_ROW_MAJOR