POV-Ray : Newsgroups : povray.programming : Vectors in C++ : Re: Vectors in C++ Server Time
6 Oct 2024 13:43:58 EDT (-0400)
  Re: Vectors in C++  
From: Christopher James Huff
Date: 16 Dec 2002 20:41:51
Message: <chrishuff-ECAA37.20371316122002@netplex.aussie.org>
In article <3dfe1e0d@news.povray.org>, Micha Riser <mri### [at] gmxnet> 
wrote:

> They hide what is really going on when using them.

That is a good thing. It is no different from using a function or 
abstract object, it hides information that is irrelevant.


> 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.


> 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.
The version using operator overloading is much easier to read, and the 
compiler could probably optimize away any significant differences.

-- 
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

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