C ++ _inline is ignored in singleton mode and displayed in my profiler. How so?

I have many classes in my project that are accessed by a singleton:

_inline GUI_BS_Map* GUI_GetBS_Map() { static GUI_BS_Map obj; return &obj; }; 

As I understand it, this code should be inlined. I have Visual Studio (2005) settings set to be embedded in any application, and my profiler (AQTime) is definitely not configured to override _inlines. However, when I look at the code, there they are, thousands of calls for each of my singleton functions. What can i skip? (I profile the debug build (to get characters for the profiler), but with speed optimization turned on.) Any suggestions are much appreciated!

+4
source share
5 answers

The compiler can ignore inline and _inline . In Visual C ++, you can try __forceinline , which does compiler built-in functions if there are no good reasons not to do this (such reasons are listed in the related MSDN article).

+9
source

Inline is just a suggestion to the compiler. It may ignore your suggestion or even built-in functions that you did not mark on the line.

I would suggest trying to move the local statics outside of your function, recompile and debug again to see if you see a behavior change. Attempting to inline this function with local statics seems to be a problem.

+1
source

inline is a semantic meaning - you cannot force the compiler to actually implement anything, it is an implementation detail, and it can laugh at you and refuse at any time.

+1
source

As said - the compiler can ignore the built-in.

In addition, it is much more likely to ignore any built-in calls when building in Debug to help with debugging (so breakpoints in built-in functions get right, etc.).

I would advise against profiling the debug version, though (if you can avoid it), since the VS compiler works differently between Debug and Release, and you may get erroneous results .....

+1
source

First, C ++ has the inline , but not _inline . Is _inline macro? Extension for the compiler? Is something related to your profiler?

Secondly, the C ++ compiler usually builds whatever he likes, and the inline is, at best, a hint that you would like to see this function nested.

The main purpose of the inline today is not so much to enable inlining optimization (which the compiler is pretty aggressive in applying, tell you), but instead to suppress the definition rule (ODR) so that the function can be fully defined in the header without risking a few definition errors from the linker.

0
source

All Articles