Hi,
I'm using a number of matrix calculations of the Eigen::MatrixXd type (dynamic size) in a component.
Some of them can be 'big' (20x32 or larger).
Until now, the matrix was resized to a certain size at configuration and then I used the full size.
Now, I want to alter part of the code, such that computations are done with matrices that change their size at run time (updateHook).
How to do this in a efficient way? I've been suggested defining a big matrix at configure time and then using the 'block' functionality of eigen.
Should this big matrix then be fixed size? or it doesn't matter, since I resize and thus allocate enough memory at configure time anyway?
(btw: Eigen is used in many places in my code, so changing to another matrix library will require an extreme good reason ;) )
Then is there also the 'port' problem:
How do I send this big matrix to another component (considering there is no option making it one component) in an efficient way? (I know Sylvain opposes such things)
AFAIK, data is copied when writing to a port, therefore allocating a 1000x1000 matrix while using only 20X5 or so is a waste of resources...
Some people seem to send pointers over ports, but this looks tricky to me and therefore I would like to avoid this.
I was wondering how this is done with std::vector, for which enough memory can be allocated with the 'reserve()' functionality. I assume, when writing a vector on a port
only the values are copied, no?
So, you could allocate a vector of size 1000, but put only 3 values in it and when writing to a port, copy only those three values. The next 'update', I can use 30 values
of my vector, without reallocation of memory and efficiently copy only 30 values when writing to a port.
Is such a thing possible for Eigen?
Any suggestions?
thanks in advance,
Nick