SFML community forums

Help => Graphics => Topic started by: rmxhaha on March 28, 2013, 05:28:12 am

Title: sf::ConveShape getPoint
Post by: rmxhaha 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...
Title: Re: sf::ConveShape getPoint
Post by: Laurent 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? ???
Title: Re: sf::ConveShape getPoint
Post by: rmxhaha 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
Title: Re: sf::ConveShape getPoint
Post by: Laurent 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.
Title: Re: sf::ConveShape getPoint
Post by: Nexus 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. (http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/)
Title: Re: sf::ConveShape getPoint
Post by: Laurent 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).