POV-Ray : Newsgroups : povray.programming : Vectors in C++ Server Time
6 Oct 2024 13:52:50 EDT (-0400)
  Vectors in C++ (Message 11 to 14 of 14)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Micha Riser
Subject: Re: Vectors in C++
Date: 17 Dec 2002 14:35:00
Message: <3dff7c63@news.povray.org>
Christopher James Huff wrote:
>> Sometimes there is also an additional temporary variable created.
> 
> You are micro-optimizing...though I am sometimes guilty of that too.
> A good compiler can often figure out the most efficient way to compile
> the code.

Well, that's probably quite true.. I am "unoptimizing" by and by things for 
sake of a better abstraction. And I have already add the + operator to the 
colour classes when I had used a nasty integration formula for the media 
stuff.

> 
>> will have to be tranlated by the compiler to
>>  tmp = c;
>>  tmp += b;
>>  a += tmp;
>> as it cannot assume that (a+b)+c is the same as a+(b+c). On the other
>> hand
>>  a.add(b); a.add(c);
>> does not need a temporary variable.
> 
> a += b; a += c;
> or:
> (a += b) += c;
> 
> No temporaries.

But you probably wouldn't write it like this when you had the + available.

> The version using operator overloading is much easier to read, and the
> compiler could probably optimize away any significant differences.
> 

I still think the programmer is more forced to think about the best 
operation sequence when one has to apply them one by one and cannot just 
put lengths of forumlas there.

- Micha

-- 
objects.povworld.org - The POV-Ray Objects Collection
book.povworld.org    - The POV-Ray Book Project


Post a reply to this message

From: Christopher James Huff
Subject: Re: Vectors in C++
Date: 17 Dec 2002 18:04:26
Message: <chrishuff-76FEFC.17593517122002@netplex.aussie.org>
In article <3dff7c63@news.povray.org>, Micha Riser <mri### [at] gmxnet> 
wrote:

> > a += b; a += c;
> > or:
> > (a += b) += c;
> > 
> > No temporaries.
> 
> But you probably wouldn't write it like this when you had the + available.

If I am worried about that I use the "x=" operators. I have written a 
vector class with these operators and I do use it in exactly this way.


> I still think the programmer is more forced to think about the best 
> operation sequence when one has to apply them one by one and cannot just 
> put lengths of forumlas there.

The problem is that he is forced to do so even when it doesn't matter.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Tony[B]
Subject: Re: Vectors in C++
Date: 18 Dec 2002 00:23:40
Message: <3e00065c@news.povray.org>
Thanks, Warp. That was very educational. And I really like that typedef
idea.

--
Anthony Bennett


Post a reply to this message

From: Tony[B]
Subject: Re: Vectors in C++
Date: 18 Dec 2002 00:26:52
Message: <3e00071c@news.povray.org>
> Thanks for your comments!

Hey, you're welcome. I'm just curious why a programmer will opt for one
style over another at times. Funny how it usually always makes sense. :)

--
Anthony Bennett


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.