The /Gf and /GF Options

By default, optimization levels /O1 and /O2 include /Gf, which allows for writable string pooling. As an optimization strategy, string pooling provides object and executable code size benefits. Writable string pooling, however, can be problematic because it is easy to unintentionally modify strings. When writing large programs, debugging this type of error can be difficult.

It is suggested that, where possible, you use /GF instead of /Gf. The /GF switch enables string pooling, but makes the string pool read-only. Similarly, if you use an optimization level that includes /Gf, you can override this switch by manually adding /GF to the compiler command line. Besides code size benefits, /GF also provides performance benefits.

Note that if you use /GF and attempt to write to a read-only string, the application will fail with an Access Violation error (ACCVIO).