November 13th, 2002, 1:24 pm
QuoteI think a good way to write it isHandle<Matrix> operator*(Handle<Matrix>, Handle<Matrix>..) {Handle<Matrix> result;.... fill the result ....return result; // it doesn't copy anything}do you agree? No, what needs reference counting in the matrix data, not the matrix itself. Have the Matrix class contain a Handle<MatrixData>. Then you can still use references to the Matrix class and avoid the coupling that the Handle<> template introduces. Copy construction and assignment is very efficient. In addition, you can have various subclasses of MatrixData (like IdentityMatrixData, TridiagonalMatrixData, ...) which know how to add/multiply/... much more efficiently given the known structure of the data. Also, I'd implement MatrixData and its subclasses as templates in case the data is integers and not doubles.