This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Overhead in returning large MatrixXd objects?

Tags: None
(comma "," separated)
matriza
Registered Member
Posts
17
Karma
0
If I'm returning by value a large MatrixXd object from a function, is the data copied (with overhead) or is there some return value optimization without copying, e.g. doing
Code: Select all
MatrixXd getX()
{
   MatrixXd X(100, 100);
   return X;
}


I'm trying to trace the slowness of some code returning largish matrices (~10K cells) compared with faster C code that is based on pointers, and thought this might be a potential cause.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
That depends on both your function and how it is used. In some case the compiler is able to get rid of the extra temporary. This is called Returned Value Optimization: http://en.wikipedia.org/wiki/Return_value_optimization. Eigen does not do anything special here.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]