C3859: Virtual memory range for PCH exceeded
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.
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.