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

Storing big matrices in STL container

Tags: None
(comma "," separated)
kde-renorm
Registered Member
Posts
9
Karma
0
AFAIK STL vector will move objects instead of copying when re-allocating internal storage as long as stored class provides move constructor/assignment.
This can be very efficient both in terms of memory and speed when working with large matrices:

Code: Select all
std::vector<MatrixXd> v;

for (int i= 0; i<100; i++)
{
    MatrixXd big_mat = ...;
    v.push_back(std::move(big_mat));

    MatrixXd another_big_mat = ...;
    v.insert(v.begin(), std::move(another_big_mat));
}


In the above example no copy of matrix should be created? Right?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hm, better use emplace_back instead of push_back(move), emplace_back should fail to compile if the type is not MoveInsertable


Bookmarks



Who is online

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