Registered Member
|
I have a question about the Eigen VectorXf. Currently, I am doing the following in a loop as follows:
Since the vector does not change size, it would be more desirable to do the following:
So what I would like to do is to overwrite the array at each loop iteration. My understanding is that the << operator does a push_back which would resize the array if I declare it as I currently do. |
Moderator
|
"<<" does not change the size of the destination, however, it is not as efficient as operator = when assigning a matrix/vector to another matrix/vector. The recommended way in your case is thus:
No resizing, no memory reallocation, unless the size of "some_whatever_array" is not some_size. |
Registered Member
|
Sorry I made a small mistake in my original post. The use I was intending was something like:
Here the sum of the size of the three array blocks equal to some_size. Is it safe to do it like this in a loop. The array size should not change but it should get refreshed with the new values at every iteration. Sorry for causing the confusion due to my stupidity. |
Moderator
|
Actually, to make << works the sum of sizes *must* equals to some_size. Otherwise, you will get an assertion error. So yes, your use case is perfectly fine, and no memory re-allocation occur.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]