When should I use __forceinline instead of inline?

前端 未结 12 1342
旧巷少年郎
旧巷少年郎 2021-01-01 09:34

Visual Studio includes support for __forceinline. The Microsoft Visual Studio 2005 documentation states:

The __forceinline keyword overrides the co

12条回答
  •  一生所求
    2021-01-01 09:38

    The compiler is making its decisions based on static code analysis, whereas if you profile as don says, you are carrying out a dynamic analysis that can be much farther reaching. The number of calls to a specific piece of code is often largely determined by the context in which it is used, e.g. the data. Profiling a typical set of use cases will do this. Personally, I gather this information by enabling profiling on my automated regression tests. In addition to forcing inlines, I have unrolled loops and carried out other manual optimizations on the basis of such data, to good effect. It is also imperative to profile again afterwards, as sometimes your best efforts can actually lead to decreased performance. Again, automation makes this a lot less painful.

    More often than not though, in my experience, tweaking alogorithms gives much better results than straight code optimization.

提交回复
热议问题