10

Today I've been adding some library headers to our precomp.h file. Then I tried to recompile in debug and got those two errors (spawned from a boost include):

error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm310' or greater

fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit

So I fixed them by increasing the memory heap size. No problem there.

My question is more about if this problem hides another one? Will I eventually have to give it more memory if I keep on adding library headers to the precomp.h? Is this the way programmers handle it, or would there be a "cleaner" way to do it?

More info:

  • Visual Studio 2013
  • c++
Community
  • 1
  • 1
Vaillancourt
  • 1,380
  • 1
  • 11
  • 42
  • 1
    All I can add is to say we did the same (only had to do it once). Since the compiler is a 32bit process, at one point you'll no longer be able to up this, but as long as it works, I see little problem. – Martin Ba Apr 28 '15 at 14:11

2 Answers2

4

The /Zm parameter does not change anything about how the code is interpreted, so it does not hide a problem in the code, other than the fact that the code requires a lot of memory to compile.

The switch only informs the compiler about the memory costs it should plan for during compilation. In VS 2013, the default precompiled header buffer size is 75 MB, which is value that a complex project can reasonably exceed. In such situations, you can use /Zm to increase the limit. Alternately, you could invest significant work into reducing the complexity of your include files.

In most cases, it is a much better use of developers' time to increase /Zm.

denis bider
  • 434
  • 3
  • 8
3

Try using the 64-bit platform toolset in Visual Studio. Doing this resolved the issue for us, and it's is one of Microsoft's recommendations for how to address the C1076 error. It's also mentioned in a blog post on precompiled header compilation issues.

To change the platform toolset, open the project's .vcxproj and add <PreferredToolArchitecture>x64</PreferredToolArchitecture> to each configuration property group as per https://stackoverflow.com/a/46069460/478380 (which is for VS 2017 but applies to 2013).

Gnat
  • 2,861
  • 1
  • 21
  • 30