Registered Member
|
Hello,
I am developing an application in C++ to control an industrial robot arm motion. The thread controlling the robot arm needs to perfom some calculations (matrices, up to dimension 6x6, multiplication and inversion as well as some quaternions operations) to which I would like to use Eigen. This thread is hard realtime and it should not miss deadlines of the task scheduller. I wonder whether the Eigen is suitable for this application. My point is that I read that eigen creates objects and allocates memory, which should not be the case in such application. Is it possible to _completely_ avoid it? Is there a drawback to the computation performance when avoiding it? Thanks Diego |
Moderator
|
Yes Eigen can avoid memory allocation when you use fixed-size scalar types. The objects will be statically allocated on the stack. E.g.
The last line will create one 6x6 matrix plus one 6x1 vector on the stack. You can even create a matrix decomposition once and reuse it several times:
You can also #define EIGEN_NO_MALLOC before including any Eigen's header to make sure malloc or the likes will never be called (it raises an assert if so, good for debugging). Finally, if your matrices have varying sizes up to 6x6, then you can declare them as: typedef Matrix<float,Dynamic,Dynamic,0,6,6> Mat; It will behave like a MatrixXf but with static allocation and matrix sizes limited to 6x6. |
Registered Member
|
I am using fixed-size types, but wether or not memory allocation uccurs seems to depend on the size of the matrix:
The allocation occurs in triangular_solve_matrix where temporaries are generated:
But as the name indicates, these should be on the stack, right? Is there a way to avoid these mallocs? From the source, I see that this behavior could probably changed with EIGEN_STACK_ALLOCATION_LIMIT; Is it ok to modify this? |
Moderator
|
Does your system support alloca? If so compiling with -DEIGEN_ALLOCA=alloca should workaround the issue. Currently alloca is enabled by default on Linux or with MSVC only.
|
Registered Member
|
ok, thanks, that worked.
The environment is mingw, which obviously supports alloca (gcc). Under Linux I don't need the define, as expected. |
Moderator
|
For the record, there is a related bug entry: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=729
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]