Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!peregrine!elroy!jpl-devvax!smythsun!david From: david@smythsun.JPL.NASA.GOV (David Smyth) Newsgroups: comp.lang.c++ Subject: Re: Generating temporaries Message-ID: <4799@jpl-devvax.JPL.NASA.GOV> Date: 14 Apr 89 19:12:10 GMT References: <8904042239.AA07890@yahi.stanford.edu> <6590094@hplsla.HP.COM> Sender: news@jpl-devvax.JPL.NASA.GOV Reply-To: david@smythsun.JPL.NASA.GOV (David Smyth) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 41 In article <6590094@hplsla.HP.COM> jima@hplsla.HP.COM (Jim Adcock) writes: ************************************************************************** *> While far from simple, or easy, ... avoids generating unnecessary *> copies or temporaries, and generates fast, compact code. *> *> The general approach is to have the binary operators, instead of *> returning a "Matrix", return a linked structure that represents ... *> *> For example: *> *> a = b + c + d; *> *> where a, b, c, and d are matrices, results in 11 machine code *> instructions that set up a linked structure saying what needs to get *> added to what, and where to put the results, followed by one call to a *> routine that copies b into a (resizing if necessary), and then adds c *> to a, then adds d to a. *> *> It seems if you mix adds and multiplies in an expression you are forced *> to generate a temporary [on heap space] which then must be reclaimed at *> destruction time. *> *> If anybody has actually figured out a cleaner way to handle these *> difficult large, variable sized object classes, please tell us. ************************************************************************** One way the is easy: DO NOT DEFINE OR USE OPERATORS FOR CLASSES! What your approach is doing is a hidden building of messages which is then given to the assignment method. That is, as you pointed out, "far from simple, or easy." **** flame on **** Supposedly, we are using C++ to make our lives simpler so we are more productive. This approach, as well as other binary operator approaches, are simply not leading to that goal. **** flame off **** Methods are simple, operators are hard. Therefore, forget the operators, don't try to write code which looks like C, and then you WILL see productivity improvements.