Compartir a través de


/O1, /O2 (Minimize Size, Maximize Speed)

Selects a predefined set of options that affect the size and speed of files.

/O1
/O2

Remarks

The following table describes /O1 and /O2.

Option

Equivalent to

Comment

/O1 (Minimize Size)

/Og/Os/Oy/Ob2/Gs/GF/Gy

Creates the smallest code in the majority of cases.

/O2 (Maximize Speed)

/Og/Oi/Ot/Oy/Ob2/Gs/GF/Gy

Creates the fastest code in the majority of cases. (default setting for release builds)

/O1 and /O2 also enable the Named Return Value optimization, which eliminates the copy constructor and destructor of a stack based return value. Consider the following sample. The Test function will not create the copy constructor or destructor. Add output statements to the constructor, destructor and copy constructor to see the effect of Named Return Value Optimization when you run the program. For more information, see Named Return Value Optimization in Visual C++ 2005.

// O1_O2_NRVO.cpp
// compile with: /O1
struct A {
   A() {}
   ~A() {}
   A(const A& aa) {}
};

A Test() {
   A a;
   return a;
}
int main() {
   A aa;
   aa = Test();
}

x86 Specific

These options imply the use of the Frame-Pointer Omission (/Oy) option.

END x86 Specific

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.

  2. Click the C/C++ folder.

  3. Click the Optimization property page.

  4. Modify the Optimization property.

To set this compiler option programmatically

See Also

Reference

/O Options (Optimize Code)

Compiler Options

Setting Compiler Options

/EH (Exception Handling Model)