Path: utzoo!attcan!uunet!munnari!vuwcomp!windy!srwmrbd From: srwmrbd@windy.dsir.govt.nz (ROBERT) Newsgroups: comp.lang.c++ Subject: Re: Continuing efforts ... Message-ID: <2042@windy.dsir.govt.nz> Date: 19 Nov 88 11:22:22 GMT Organization: DSIR, Wellington, NZ Lines: 28 Bjarne writes .... >Assume a class Matrix for which creation/copying/destruction is so expensive >that you'd rather not have temporary variables introduced: > > f() { > Matrix a,b,c; > // ... > a = b + c; // yuck: temporary used > a = a * c; // yuck: temporary used > } > In my attempts to write an array package to solve this problem I have two classes of array, eg IA and tIA. The IA class has the usual constructors and destructors. However the tIA class has no destructor and the rule is that anything that uses a tIA object must destroy it or recycle its space. All operators such as + - etc return tIA objects and = is defined just to convert tIAs to IAs by redirecting pointers. You need different versions of operator+ for when the arguments are IA or tIA so that it doesn't generate unnecesary arrays when you write x = a + b + c; . So far the package seems to work transparently to the user who isn't meant to know anything about tIAs, and should avoid almost all unnecesary copying and much unnecessary space allocation. (a = a * c; still has an unnecessary space allocation). Robert Davies