Alexander Stippler wrote:
I've several methods which get large objects as parameters like:
QRDecomposition qr_decomposition(const DoubleDenseMatrix &A);
My question is simple:
Should the line above be the preferred way?
Or should the parameter be given like
QRDecomposition qr_decomposition(DoubleDenseMatrix A);
I know the difference in semantics.
But does it make some essential difference for the compiler?
These two definitions are equivalent
as far as the calling program is concerned.
Is it better to have the compiler do the copy
Or to do it by oneself inside the method?
It doesn't matter if you implementation calls for a copy to be made.
Any performance differences?
No.
Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library (SVMTL)
http://www.netwood.net/~edwin/svmtl/
(svmtl/src/matrix/Matrix.ccP: line #481-517)
Most implementations [in any computer programming language]
provide a method to perform the decomposition *in-place*:
DoubleDenseMatrix& qr_decomposition(DoubleDenseMatrix &A);
The QR decomposition is "packed" back into DoubleDenseMatrix A
in a format defined be the implementation
(and, in this case, a reference to A is returned).
This isn't a very good Application Program Interface (API)
because a DoubleDenseMatrix object has effectively
been converted into a QRDecomposition object
and is no longer a meaningful DoubleDenseMatrix object.
Obviously, this will certainly lead some unwary application programmer
to grief.