调试构建中的内联函数 (Visual C++ 2008)

发布于 2024-12-06 03:32:44 字数 197 浏览 1 评论 0原文

我正在使用的游戏引擎在调试构建中速度太慢,并且无法调试游戏。我想要的一件事是编译器内联小函数(特别是在 Vector/Matrix 和容器类中)。这可能会也可能不会加快调试构建中的游戏速度。在进行大量分析并试图找出瓶颈之前,我想我应该先尝试一下,因为我只需做最少的工作,结果可能会很有希望。

那么,有没有办法让 Visual C++ 编译器在调试版本中内联函数呢?

The game engine I am working with is too slow in the 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回梦 2024-12-13 03:32:44

项目选项-> C/C++->优化->内联函数扩展。将其转换为 /Ob2。还要确保调试信息格式(在 C/C++ -> 常规下)未设置为 /ZI(如果是,则将其设置为 /Zi)。在调试配置中执行此操作。

在发布版中,内联函数扩展是由其他优化设置隐含的,因此即使默认情况下所有配置都为该设置设置“默认”,但行为确实不同。

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

(原始海报)
我相信调试版本应该具有与发布相同的内联扩展行为;真的没有理由不这样做。

(编辑)
不这样做的主要原因是,在调试器中单步执行代码时,内联的函数根本不会显示,从而导致“不可见”代码。

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.

恋竹姑娘 2024-12-13 03:32:44

您混淆了两个编译器选项。 /O 影响优化,包括内联。 /ZI 创建用于调试的 PDB 文件。它们可以独立设置。

不过,克隆“调试”配置并使用 /O1/ZI 创建“调试优化”配置可能会很有用。

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.

雨夜星沙 2024-12-13 03:32:44

您可以尝试 __forceinline 。请务必阅读该页面上有关调试版本的信息(关闭 /Ob0 选项)。

我怀疑这不会对性能产生太大影响。如果您还没有尝试的话,另一件事就是向发布版本添加符号。它对于调试很多问题来说效果相当好。

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.

淡忘如思 2024-12-13 03:32:44

DEBUG 由 Visual Studio 在调试模式下编译项目时定义,因此:

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

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

#ifdef DEBUG
  inline void fn() {
#else
  void fn() {
#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文