Search code examples
c++singletoninlineaqtime

C++ _inline is being ignored in a singleton and showing up in my profiler. How come?


I have a lot of classes in my project accessed by a singleton like so:

_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 the Visual Studio (2005) options set to inline anything suitable, and my profiler (AQTime) is definitely not set to override the _inlines. However, when I profile the code, there they are, thousands of calls to each of my singleton functions. What could I be missing? (I'm profiling a debug build (to get symbols for the profiler) but with all of the speed optimisations turned on.) Any suggestions much appreciated!


Solution

  • The compiler is free to ignore inline and _inline. In Visual C++ you can try __forceinline that makes the compiler inline functions unless there're serious reasons not to do so (such reasons are listed in the linked MSDN article).