Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::ConveShape getPoint  (Read 2129 times)

0 Members and 1 Guest are viewing this topic.

rmxhaha

  • Newbie
  • *
  • Posts: 8
    • View Profile
sf::ConveShape getPoint
« on: March 28, 2013, 05:28:12 am »
I get a little bit curious about one function in sf::ConvexShape class. In my version of SFML 2.0 there is a getPoint function inside sf::ConvexShape class.
it returns  Vector2f...

Why is that ?
Why not const Vector2f& ?

is there any perpose in doing that ?
I mean I've tried before that accessing getPoint took around 1.8 times accessing a direct float took. Which could only means a copy happened

Although it doesn't give much a difference if there is only a few thousand getPoint call but I am worried that it might be a bottleneck which is less likely to happened but I still am worried...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::ConveShape getPoint
« Reply #1 on: March 28, 2013, 08:00:34 am »
It's a copy because it's inherited from the base class, which cannot assume that every derived class stores its points -- and they usually don't, they compute it on the fly, except for sf::ConvexShape.

And you're worried about... what? Performances? So you really think that copying two floats, compared to copying a pointer and dereferencing it (that's what a reference is) will be much slower and impact your overall performances? Are you serious? ???
Laurent Gomila - SFML developer

rmxhaha

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::ConveShape getPoint
« Reply #2 on: March 28, 2013, 09:55:42 am »
Yup I am serious, I am bad at geometry and doing a lot of brute force calculation which require to access more. Maybe this won't be a problem for now.... I will be back when this has become a problem.

Thanks for your answer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::ConveShape getPoint
« Reply #3 on: March 28, 2013, 10:38:56 am »
I doubt that it will ever become a problem.

And by the way, don't draw conclusions so easily. Passing/returning by value vs by reference can give surprising results if you take the time to do some serious tests. I once read a good article about it but I can't find it.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::ConveShape getPoint
« Reply #4 on: April 01, 2013, 11:41:46 am »
I will be back when this has become a problem.
And please come back with profiling results, not just assumptions. With this kind of micro-optimizations, it's already easy to measure in a wrong way, while guessing is just plain nonsense.

I once read a good article about it but I can't find it.
Maybe you mean Want Speed? Pass by Value.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::ConveShape getPoint
« Reply #5 on: April 01, 2013, 04:42:48 pm »
Quote
Maybe you mean Want Speed? Pass by Value.
Nop, it was a blog article written by a Qt guy. And it was a benchmark of passing various sizes/types by copy/reference on various OSes/architectures, with very detailed conclusions (like: "it's better to pass up to 64 bits by value on x86_64 Linuxes", things like that).
Laurent Gomila - SFML developer

 

anything