/Ob(内联函数展开)/Ob (Inline Function Expansion)

控制函数的内联扩展。Controls inline expansion of functions. 默认情况下,在进行优化时,将在编译器对所有函数(通常称为 自动内联)上自行决定扩展。By default, when optimizing, expansion occurs at the compiler's discretion on all functions, often referred to as auto-inlining.

语法Syntax

/Ob{0 | 1 | 2 | 3}/Ob{0|1|2|3}

/Ob{0 | 1 | 2}/Ob{0|1|2}

参数Arguments

00
/Od下的默认值。The default value under /Od. 禁用内联扩展。Disables inline expansions.

11
仅允许在类声明中定义的 c + + 成员函数中对标记为 内联__inline__forceinline或的函数进行扩展。Allows expansion only of functions marked inline, __inline, or __forceinline, or in a C++ member function defined in a class declaration.

22
/O1/O2下的默认值。The default value under /O1 and /O2. 允许编译器展开未显式标记为 "无内联" 的任何函数。Allows the compiler to expand any function not explicitly marked for no inlining.

三维空间3
此选项指定比 /Ob2 更严格的内联,但具有相同的限制。This option specifies more aggressive inlining than /Ob2, but has the same restrictions. 从 Visual Studio 2019 开始,可以使用 /Ob3 选项。The /Ob3 option is available starting in Visual Studio 2019.

备注Remarks

编译器将内联扩展选项和关键字视为建议。The compiler treats the inline expansion options and keywords as suggestions. 不能保证所有函数都将以内联方式展开。There's no guarantee that any function will be expanded inline. 您可以禁用内联扩展,但是不能强制编译器内联特定函数,即使使用关键字时也是如此 __forceinlineYou can disable inline expansions, but you can't force the compiler to inline a particular function, even when using the __forceinline keyword.

若要将函数作为内联展开的候选项排除,可以使用 __declspec (noinline) ,或者使用 #pragma auto_inline () #pragma auto_inline () 方法 To exclude functions from consideration as candidates for inline expansion, you can use __declspec(noinline), or a region marked by #pragma auto_inline(off) and #pragma auto_inline(on) directives. 有关为编译器提供内联提示的另一种方式的信息,请参阅 #pragma 内部 指令。For information on another way to provide inlining hints to the compiler, see the #pragma intrinsic directive.

备注

通过分析测试运行收集的信息会替代由于你指定了 /Ob/os/ot 而生效的优化。Information that is gathered from profiling test runs overrides optimizations that would otherwise be in effect because you specified /Ob, /Os, or /Ot. 有关详细信息,请参阅按配置优化For more information, see Profile-Guided Optimizations.

在 Visual Studio 开发环境中设置此编译器选项To set this compiler option in the Visual Studio development environment

  1. 打开项目的“属性页” 对话框。Open the project's Property Pages dialog box. 有关详细信息,请参阅在 Visual Studio 中设置 C++ 编译器和生成属性For details, see Set C++ compiler and build properties in Visual Studio.

  2. 选择 "配置属性" " > c/c + + > 优化" 属性页。Select the Configuration Properties > C/C++ > Optimization property page.

  3. 修改 内联函数展开 属性。Modify the Inline Function Expansion property.

/Ob3 选项在 内联函数展开 属性中不可用。The /Ob3 option isn't available in the Inline Function Expansion property. 设置 /Ob3To set /Ob3:

  1. 打开项目的“属性页” 对话框。Open the project's Property Pages dialog box. 有关详细信息,请参阅在 Visual Studio 中设置 C++ 编译器和生成属性For details, see Set C++ compiler and build properties in Visual Studio.

  2. 选择“配置属性”“C/C++”“命令行”属性页 > > 。Select the Configuration Properties > C/C++ > Command Line property page.

  3. 其他选项 中,输入 /Ob3Enter /Ob3 in Additional Options.

以编程方式设置此编译器选项To set this compiler option programmatically

请参阅See also

/O 选项 (优化代码) /O Options (Optimize Code)
MSVC 编译器选项MSVC Compiler Options
MSVC 编译器 Command-Line 语法MSVC Compiler Command-Line Syntax