Rediger

Del via


/GF (Eliminate Duplicate Strings)

Enables the compiler to create a single copy of identical strings in the program image and in memory during execution. This is an optimization called string pooling that can create smaller programs.

Syntax

/GF

Remarks

If you use /GF, the operating system does not swap the string portion of memory and can read the strings back from the image file.

/GF pools strings as read-only. If you try to modify strings under /GF, an application error occurs.

String pooling allows what were intended as multiple pointers to multiple buffers to be multiple pointers to a single buffer. In the following code, s and t are initialized with the same string. String pooling causes them to point to the same memory:

char *s = "This is a character buffer";
char *t = "This is a character buffer";

Note

The /ZI option, used for Edit and Continue, automatically sets the /GF option.

Note

The /GF compiler option creates an addressable section for each unique string. And by default, an object file can contain up to 65,536 addressable sections. If your program contains more than 65,536 strings, use the /bigobj compiler option to create more sections.

/GF is in effect when /O1 or /O2 is used.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

  2. Select the Configuration Properties > C/C++ > Code Generation property page.

  3. Modify the Enable String Pooling property.

To set this compiler option programmatically

See also

MSVC Compiler Options
MSVC Compiler Command-Line Syntax