Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Vaalegk

Any performance diference ?(operators)

This topic is 5802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,my question is : Is there any diference between overloading a operator or writing a general operator, well a dont know if the question is clear, but mybe the fallowing code can explain it better class Vector { "some members" "some methods if needed" Vector operator + (Vector &r); }; OR class Vector { "some members" "some methods if needed" }; Vector operator+(Vector &a,Vector &b); I mean , is there any performance hit? wich one is better?

Share this post


Link to post
Share on other sites
Advertisement
There's no performance difference. Implement operations outside the class if possible with the class' public interface, otherwise implement the operations inside the class. Also take a look at Boost operators to reduce your workload. The arguments should have const modifier.

[edited by - civguy on December 4, 2002 3:32:38 PM]

Share this post


Link to post
Share on other sites
The two are identical in performance. Ronin, all member functions require an extra pointer to be put on the stack, the "this" pointer.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
quote:
Original post by Ronin Magus
Well, it seems to me the member function would be better, since it only requires pushing a reference to one vector onto the stack for the function call (instead of two).

But someone who knows better about the architecture of functions could probably tell you better.

http://roninmagus.hopto.org
acronymfinder.com - Find any acronym you need!


The this pointer needs to be pushed on the stack to, so I don''t think there is a difference in performance, in both cases they need to push two things on the stack.

Share this post


Link to post
Share on other sites
You should make it a member function without a compelling reason to do otherwise. The possibility that it might make a performance differance is not a compelling reason. That you actually have a performance problem that can be resolved by doing that is a compelling reason. Big differance between the two. It isn''t going to take much to change it should you ever find a compelling reason to do so. Far too many people spend far too much time optimizing something that makes no differance while failing to optimize something that does. I''ve spent many years optimizing other people''s code and personally I would prefer most make no attempt to do so. A well coded program is easily optimized even if no consideration is given to optimization. People who do a bunch of screwy things in the name of performance most often create programs that require major modifications in order to resolve the real performance problems. The worst cases being where what they did in the name of performance is the actual cause of the performance problem. As a general rule you cannot guess what you would know if you only knew more.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!