Re: [eigen] To initialize or not to initialize

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Benoit Jacob wrote:
2010/4/16 Adolfo Rodríguez Tsouroukdissian <adolfo.rodriguez@xxxxxxxxxxxxxxxx>:
Looking into the code of various decompositions I've seen that the
constructors for input matrix are sometimes implemented like this (dummy
example):

fooDecomp(const MatrixType& matrix) : m_mat(matrix.rows(), matrix.rows())
{
  compute(matrix);
}

and sometimes like this:

fooDecomp(const MatrixType& matrix) // <- Notice no initialization
{
  compute(matrix);
}

First of all, I'd like to propose uniforming this (I could do it), but I
also wanted to know how big a difference is there between the two
alternatives.

The better version is the one with the initialization list. The other,
without initialization list, means that in case of a dynamic matrix,
it is initialized with size 0 and then resized by the compute()
method. This amounts almost exactly to the same, there is just a tiny
bit of inefficiency here.


Init list also adds exceptions safety



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/