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

Resize without reallocation

Tags: None
(comma "," separated)
DikobrAz
Registered Member
Posts
3
Karma
0

Resize without reallocation

Sun May 06, 2012 9:42 am
I'm using Eigen to construct dynamically an optimization problem. To do this I start with empty problem description matrices and iteratively append other matrices using conservativeResize and block operations.

Accordnigly to http://eigen.tuxfamily.org/dox/classEigen_1_1PlainObjectBase.html#ac20f895ce9b73fa7447196855c0d0758 resize always reallocate data with exception of unchanged dimensions. So the proposed method for constructing matrices will reallocate memory each time matrix is appended. Is there a way to do it without reallocation? I.e. allocate enough memory for the initial matrix, so the latter append operations and thus resizing won't lead to reallocation.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Resize without reallocation

Mon May 14, 2012 1:49 pm
You can do it manually using either:
1) a preallocated buffer, and a Map object that you remap (see the end of the doc of the Map class to see how to remap: http://eigen.tuxfamily.org/dox-devel/cl ... _1Map.html)
2) a big Matrix, and a Block<> that you dynamically reconstruct (you can use the same placement new to reconstruct the Block object)
johnm1019
Registered Member
Posts
46
Karma
0

Re: Resize without reallocation

Fri Jun 01, 2012 8:25 am
conservativeResize was briefly discussed here :)

viewtopic.php?f=74&t=97410


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell