0 out of 1 rated this helpful - Rate this topic

/GF (Eliminate Duplicate Strings)

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

/GF

/GF pools strings as read-only.

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. 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 as 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";
NoteNote:

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

/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 How to: Open Project Property Pages.

  2. Click the C/C++ folder.

  3. Click the Code Generation property page.

  4. Modify the Enable String Pooling property.

To set this compiler option programmatically

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
/GF seems to cause each C string to get its own section?
/GF seems to cause each C string to go into its own section in this case:

typedef struct struct_name {
char *key;
char *value;
} struct_name;

struct_name sv[] = {{"First Key", "First Value"}
{"Second Key", "Second Value"}};

This may lead to a requirement for /bigobj if there are enough C strings in the program. That, in turn, may lead to spending an entire day trying to track down mysterious failures in regsvr32 before giving up and choosing a different approach altogether.
Advertisement