Registered Member
|
Hello,
I would like to define the possible maximum size of a matrix and resize the matrix within these bounds without the use of temporaries. Therefore, I set Matrix template parameters 4 and 5 to the corresponding maximum value. A call to conservativeResize uses only the memory of the old matrix if only rows for RowMajor or cols for ColMajor are changed. Is it possible to change both dimensions without mem reallocation? Would it be a better solution to use blocks to a matrix of constant size to emulate the behaviour? Thanks in advance. Korbi |
Moderator
|
when you specify the maximal sizes via the last two template parameters, then the matrix data is statically allocated on the stack, and so it cannot be reallocated. However, a Matrix object guarantee that the data are sequentially stored in memory, no padding is allowed, therefore we still have to copy the data during a conservativeResize. If you can tolerate padding, then yes you can use a Block, e.g.:
MatrixXd m_storage(maxrows, maxcols); Block<MatrixXd> m(m_storage,0,0,rows,cols); |
Registered Member
|
Hi GGael,
thanks for the explanation. Using blocks will then be the right way in my implementation. Korbi |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]