What does “Optimize Code” option really do in Visual Studio?

前端 未结 3 2064
礼貌的吻别
礼貌的吻别 2020-11-28 05:04

Name of the option tells something but what Visual Studio/compiler really do and what are the real consequences?

Edit: If you search google you can find this address

3条回答
  •  一生所求
    2020-11-28 05:51

    Without optimizations the compiler produces very dumb code - each command is compiled in a very straightforward manner, so that it does the intended thing. The Debug builds have optimizations disabled by default, because without the optimizations the produced executable matches the source code in a straightforward manner.

    Variables kept in registers

    Once you turn on the optimizations, the compiler applies many different techniques to make the code run faster while still doing the same thing. The most obvious difference between optimized and unoptimized builds in Visual C++ is the fact the variable values are kept in registers as long as possible in optimized builds, while without optimizations they are always stored into the memory. This affects not only the code speed, but it also affects debugging. As a result of this optimization the debugger cannot reliably obtain a variable value as you are stepping through the code.

    Other optimizations

    There are multiple other optimizations applied by the compiler, as described in /O Options (Optimize Code) MSDN docs. For a general description of various optimizations techniques see Wikipedia Compiler Optimization article.

提交回复
热议问题