Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Can I eliminate these temporary objects?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David Vandevoorde  
View profile  
 More options Mar 18 1995, 3:01 am
Newsgroups: comp.lang.c++
From: vande...@pleiades.cs.rpi.edu (David Vandevoorde)
Date: 17 Mar 1995 19:36:53 GMT
Local: Fri, Mar 17 1995 2:36 pm
Subject: Re: Can I eliminate these temporary objects?
In article <3kaqnn$...@aggedor.rmit.EDU.AU>,

David Hoadley <s840...@minyos.xx.rmit.EDU.AU> wrote:
>Consider the following code. I have created a matrix class for
>complex numbers, called DCMatrix, and an operator* function:

>int main()
>{
>   DCMatrix A(2,3, complex(0.0,0.0));
>   DCMatrix B(3,4,complex(1.0,0.0));
>   DCMatrix C(2,4);
>//  fill A and B with stuff
>   C = A * B;
>   return (0);
>};

>If I trace its execution, I see:

>constructor --A(2,3)
>constructor --B(3,4)
>constructor --C(2,4)

>operator*
>constructor --Result(2,4)    (from declaration within operator*)
>copy constructor --anon(2,4) (values copied from Result to new anon)
>destructor  --Result
>operator=                    (copies values from anon to C)
>destructor  --anon

>destructor  --C
>destructor  --B
>destructor  --A

>Result is a temporary matrix which I would rather not have, but I
>could not see how to write operator* without it. anon is another
>temporary matrix, which I didn't declare.

>Is is possible to implement this without these two temporary matrices?

Yes, but it's not so easy to make a general robust code that achieves
this.

>If not, which I fear, can I at least avoid the creation of one of them
>(presumably anon)?

>Thanks for any help,
>David.

I would suggest you take a look at two packages.

The first one is "NewMat" ("newmat08" is the latest release, I believe)
by Robert Davies (robe...@kauri.vuw.ac.nz). You may get it by ftp from
plaza.aarnet.edu.au in /usenet/comp.sources.misc/volume47/newmat08.
It uses a dynamic expression analysis technique to handle this problem.
For large objects where operations are not only "elementwise" (e.g.,
matrix addition is an elementwise operation, whereas matrix multiplication
is not) this might well be the best way to go.

The second package is my own valarray<Troy> (get it by anonymous ftp from
ftp.cs.rpi.edu in pub/vandevod/Valarray). It is _not_ a matrix library,
but an implementation of a numerical array modeled after the specs for a
similar array included in the current working paper of the ISO committee.
It makes heavy use of class and function templates to avoid the generation
of temporary arrays altogether (but the supported operations are "element-
wise" which makes things a whole lot simpler). It comes with some technical
discussion that reviews other alternatives.

>-------------------------------------------------------------------------- ---
>David Hoadley                         Internet: s840...@minyos.xx.rmit.edu.au
>Electrical Engineering, RMIT
>Melbourne, Australia                  Ph: +61 3 660-4847, Fax: +61 3 660-2007

        Daveed

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.