Reply to topic

Overhead in returning large MatrixXd objects?

matriza
Registered Member
Posts
15
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
2194
Karma
15
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.

 
Reply to topic

Bookmarks



Who is online

Registered users: 16777216, alake, Baidu [Spider], Bing [Bot], edmael, Exabot [Bot], garthecho, Google [Bot], Hans, joshaughnessy, koriun, Majestic-12 [Bot], north, raymondsarver, urgo, verbalshadow, Yahoo [Bot]