SFML community forums
Help => Graphics => Topic started 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...
-
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? ???
-
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
-
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.
-
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/)
-
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).