Advantage of using a static member function instead of an equivalent non-static member function?
There is absolutely no performance difference between static member functions and free functions.
From a design perspective, it sounds like the function in question has very little to do with Bullets, so I would favour putting it in a utility library somewhere, there is no runtime overhead in doing this, only extra developer effort if you don't already have such a library.
Regarding the original question, if the function doesn't obviously pertain to a particular class, then it should be a free function. At the most, it should belong to a namespace, to control its scope. And even if it pertains to a class, most times, I would still prefer the free function unless the function requires access to private members.
Typically static
is used if possible, to eliminate the need for an object and eliminate the extraneous this
argument.
But one exception is in functors: classes which define operator()
so objects can be "called" as functions. Idiomatically such an operator()
is declared inside the class {}
block, which makes it inline
.
Then, if the function is small, it is inlined into the calling function and the this
pointer is optimized out.
If the function is large, it may not be inlined. But the miniscule disadvantage of having an extra argument is probably dwarfed anyway.