views:

65

answers:

3

Is there a way to tell the compiler to inline wherever it sees it to be useful? I thought it did this by default, but adding a few inline to my game loop functions improved performance by a good 30%.

Thanks

+1  A: 

The compiler will generally inline functions if it will seem to boost performance, however, it might avoid this if you don't enable optimizations (e.g debug mode). If you enable optimizations, it should probably inline for you.

Maister
+3  A: 

The /Ob option

Note that the compiler can't auto-inline functions across compilation units unless you use Whole Program Optimization (/GL).

Ben Voigt
+2  A: 

Visual C++ will do auto inline expansion if you tell it to, via the /Ob2 switch (but only if optimizations are turned on, e.g., /O2).

It could be that this was turned off, or perhaps the compiler isn't as aggressive at inlining as you want. In the latter case, use the inline keyword (which you have done :D).

Seth