srwmrbd@windy.dsir.govt.nz (ROBERT) (11/19/88)
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
baud@gt-eedsp.UUCP (Kurt Baudendistel) (11/30/88)
In article <2042@windy.dsir.govt.nz> srwmrbd@windy.dsir.govt.nz (ROBERT) writes: >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. >... well, this is a passable method for implementation, but it gets out of hand very quickly. try adding sub-array constructs to this method---to do it you have to add yet another data type. then there are vectors. how many vector types do you need? how about all of those conversions and dummy member functions?!!! after some experiment, i've decided that a run-time (rather than a compile- time) method is easier to implement and much less costly in terms of complexity of the class definition. hopefully, the gnu c++ library will release a good array package to the masses early next year (january?) so we can forget about these types of discussions. kurt -- Kurt Baudendistel --- GRA Georgia Tech, School of Electrical Engineering, Atlanta, GA 30332 uucp: ...!{allegra,hplabs,ulysses}!gatech!gt-eedsp!baud internet: baud%gt-eedsp@gatech.edu
srwmrbd@windy.dsir.govt.nz (ROBERT) (12/05/88)
baud@gt-eedsp.UUCP (Kurt Baudendistel) writes (<575@gt-eedsp.UUCP>) >>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. ... >Well, this is a passable method for implementation, but it gets out of >hand very quickly. Try adding sub-array constructs to this method---to >do it you have to add yet another data type. Then there are vectors. How >many vector types do you need? how about all of those conversions and >dummy member functions?!!! >After some experiment, I've decided that a run-time (rather than a >compile- time) method is easier to implement and much less costly in >terms of complexity of the class definition. Hopefully, the gnu c++ >library will release a good array package to the masses early next year >(january?) so we can forget about these types of discussions. I presume the runtime package includes a Boolean variable in the array definition which indicates whether the space may be recycled. I started out along those lines and then switched to the two class approach because it seemed as though the C++ compiler could do the administration. You need about the same code in each case but the C++ compiler has to work a lot harder in my case (really too hard on a PC running Glockenspiel). Either approach reduces the amount of copying that a naive array package would use - and this was the point of the original comment. Hopefully Gnu C++ will release a good array package - but if it is Gnu won't that mean we can't use it on confidential or commercial projects?