开发者

Inline functions in debug build (Visual C++ 2008)

The game engine I am working with is too slow in t开发者_C百科he debug build and is impossible to debug the game. One of the things I would like is for the compiler to inline small functions (especially in Vector/Matrix and container classes). This may or may not speed up the game in debug build. Before profiling heavily and trying to figure out bottlenecks I thought I would try this first as I would have to do minimal work and the results may be promising.

So, is there a way to get the Visual C++ compiler to inline functions in debug builds?


Project options -> C/C++ -> Optimization -> Inline Function Expansion. Turn this to /Ob2. Also make sure that Debug Information Format (under C/C++ -> General) isn't set to /ZI (set it to /Zi instead if it is). Do this in your Debug configuration.

In Release, inline function expansion is implied by other optimization settings, so even though by default all configurations say "Default" for the setting, the behavior is indeed different.

http://msdn.microsoft.com/en-us/library/47238hez.aspx

(original poster) I believe Debug builds should have inline expansion behavior the same as release; there's really no reason not to.

(editor) The main reason to not do this is that functions that do get inlined won't show up at all when stepping through code in the debugger, resulting in "invisible" code.


You're confusing two compiler options. /O influences optimization, including inlining. /ZI creates the PDB file for debugging. They can be set independently.

It may be useful to clone the "Debug" configuration, though, and create a "Debug-optimized" configuration with both /O1 and /ZI.


You might try __forceinline. Be sure to read about debug builds on that page (turn off the /Ob0 option).

My suspicion is that this will not change the performance very much. Another thing to try if you haven't already is just to add symbols to a release build. It works fairly well for debugging a lot of issues.


DEBUG is defined by Visual Studio when a project is compiled in Debug mode so:

#ifdef DEBUG
  inline void fn() {
#else
  void fn() {
#endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜