wrote in message news:b2g7nj+6gee@eGroups.com...
| A question on use of the matrix and vector classes:
|
| Should I:
...
| matrix<double> foo(const matrix<double> a)
...
| void foo(matrix<double>& r, const matrix<double> a)
...
| In other words: is it expensive to construct the temporary in case
| one? As I understand, the class would need an underlying 'copy on
| write' to be cheap, similar as strings do.
By default, the copy constructor of boost::numeric::ublas::matrix
appears to copy its representation in a newly allocated block.
As far as I can tell, this behavior could be customized by
using a custom storage type (the third template parameter).
However, many optimizing compilers are able to eliminate
unnecessary copying of the return value of a function.
(This is called RVO or NRVO for Return Value Optimization and
Named..., depending on how the function is written).
For example, MSVC suppresses the unnecessary copy,
even in Debug mode with no optimizations enabled.
So I think you should prefer the interface which is more
natural to use:
matrix<double> foo(const matrix<double> a)
I hope this helps.
--
Ivan Vecerina, Dr. med. <> http://www.post1.com/~ivec
Soft Dev Manger, xitact <> http://www.xitact.com
Brainbench MVP for C++ <> http://www.brainbench.com