#117352 - keldon - Sun Feb 04, 2007 2:25 am
Code: |
Matrix m7 = m0 * (m1+m2) * (m3 * m4) * m5 * m6; |
Let's take the given line of code and assume anything you want, so long as we all can assume that there will be no memory leaks. In a managed environment with operator overloading (such as the .net CIL) the example code would have created many instances of the Matrix class, and disposed of them. Is this how it should be handled? How many new instances would/should be created?
My answer is 2; only two should be created. However with the current languages you are going to see 6 new instances created with this line of code. In fact if these variables were only created for the creation of m7 and will never be used again then we do not need to create any new instances, we can simply use existing objects. No language allows for this, in order for this sort of feature to be able to be handled by the compiler there must be two version of the overloaded operators: a mutable version and an immutable version.
Is there an application for an object that has both mutable and immutable types of access?
Discuss!!