Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C3859: Virtual memory range for PCH exceeded

I get this error message from time to time (not every time) I compile (EDIT: sorry, I didn't make myself clear here: I actually meant "rebuild") my mixed-mode project. And Visual Studio tells me to "recompile with a command line option of '-Zm114' or greater". In principle no problem, I just do as VS tells me.

But currently, there are two problems with this:

  1. Why does it not occur every time I do a rebuild? If I understand correctly, the compiler ran out of memory while compiling my project. So if I do a rebuild, which cleans all prior work, shouldn't it run out of memory the next time too, if I don't change anything?

  2. To be on the safe side, I already have specified a value of 120 for Zm (ie Zm120) in all configurations of this project. Why do I get an error message with this lower value? Or is the suggested value of 114 just a wild guess of VS?

like image 432
derpirscher Avatar asked Jul 20 '16 11:07

derpirscher


3 Answers

I know this is old but I ended up here so I might as well answer.

There is a great article about PCH problems here.

1) Why does it not occur every time I do a rebuild?
This is a bit complex to answer surely. Since it is not happening every time, it could be several issues. It is most likely due to memory allocation. From the article :

  • Fragmentation of the virtual memory address range(s) required by the PCH before CL.EXE is able to load it into memory.
  • Failure of the Windows OS under heavy loads to increase the pagefile size within a certain time threshold.

It could also be a Pagefile size problem (most likely on Virtual machines) but I believe you would have a message similar to this :

c1xx : error C3859: Failed to create virtual memory for PCH [...Project.vcxproj] c1xx: note: the system returned code 1455: The paging file is too small for this operation to complete

2) Why do I get an error message with this lower value? (Zm114 instead of Zm120)
Make sure that the Zm120 modifications handle all the build configurations (Release|Debug) and Platform (x86|x64).

It could also help to set PreferredToolArchtecture to x64:

If you’re using MSBuild from the command line you can pass /p:PreferredToolArchtecture=x64 to MSBuild. If you’re building with MSBuild from within Visual Studio, you can edit your .vcxproj file to include a PropertyGroup containing this property.

This one is easily overlook, but those kind of problem also happen when the precompiled header is just too big. Doing a little cleanup might be a good idea as well.

like image 147
Scott Avatar answered Oct 24 '22 00:10

Scott


Our builds were failing in our Jenkins CI pipeline due to PCH and memory issues.

Our problem was that WinRM had a low limit for the allowed shell memory.

After updating this, and setting it to unlimited, we are not getting any more memory related issues with builds.

winrm.cmd set winrm/config/winrs @{MaxMemoryPerShellMB="0"}

Some background:

  • Our Windows builds are done in Amazon AWS AMIs
  • WinRM is the remote shell that Jenkins uses to connect to the AMI
  • We use packer to set up the AMIs
  • The above command was added to the packer bootstrap file
  • The above command comes from: Configure Maximum Powershell Memory in Windows Server
  • More about the quota management: Quota Management for Remote Shells
like image 20
CJCombrink Avatar answered Oct 24 '22 01:10

CJCombrink


I was running into this compiling a large code base on a local VM. Tried upping the page file size etc and didn't work. The only thing that worked in my case was to disable dynamic memory in the Hyper-V VM setting and give the VM more RAM, 8GB -> 16GB.

Apparently VS allocates it's memory up-front so it only uses the initial value given to the VM and won't trigger any dynamic memory changes.

like image 30
Geordie Avatar answered Oct 24 '22 00:10

Geordie