From: Theodore P. <The...@so...> - 2004-04-15 20:28:27
|
fr...@cl... said: > If I understand this correctly, the call to test_six() copy constructs > a new blitz array on the stack (which still represents the same data, > though). That's done 10000 times! (As opposed to just passing a > pointer in the other cases.) > What would a reference change? Just a guess... Not much, but it won't hurt either. Remember that blitz arrays are passed by reference (ie the array data is not copied) so that you end up copying just a few bytes of bookeeping (sizes, strides, ...). That being said, this "pass by reference" semantics is really a source of obscure bugs when using blitz. I particularly remember having done a: MyBlitzDerivedClass operator+=(something) { ... } MyBlitzDerivedClass operator+(something) { MyBlitzDerivedClass res = *this; return res += something; } in a code full of matrices and vectors. Guess what it took me about one or two weeks to figure out what was failing.... And it was not the first time. I'm not quite sure what it gains since people still can use references to pass arrays. Returning arrays is more a problem, but I guess it can be done and the RVO trick should minimize the problem. Had anyone tried to determine the performance impact of having a true "pass by copy" semantics (replace the copy constructor by the copy function) semantics ??? -------------------------------------------------------------------- Theodore Papadopoulo Email: The...@so... Tel: (33) 04 92 38 76 01 -------------------------------------------------------------------- |