How can I fix PCH memory errors after c++20?

Markus Andhoy 16 Reputation points
2022-06-16T06:26:48.357+00:00

Greetings, I come to you with memory management issues.

After C++20 came out, we have assigned this to be the standard language to our projects.
We've been using PCH for a good while already, and until C++20 came out, there hasn't been any issues.

Now we're getting a steady supply of compilation errors that looks like
C1076 compiler limit: internal heap limit reached
C3859 Failed to create virtual memory for PCH

This comes when I rebuild the solution, and the errors consist until I've built about 2-3 times. The errors then disappear and the project builds and runs as it should.
However this causes issues with our automated testing scripts, as they simply find compilation errors and ultimately end up failing.

I'm not too well versed in memory management nor PCH, but ultimately it looks like there's not enough space for the compilation of the entirety of our PCH.

Any ideas how to get past these errors?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,730 questions
{count} vote

3 answers

Sort by: Most helpful
  1. Doaa Abd El Kader 31 Reputation points
    2022-06-16T11:49:02.6+00:00

    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 :

    1) Fragmentation of the virtual memory address range(s) required by the PCH before CL.EXE is able to load it into memory.

    2) 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 :

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

    1 person found this answer helpful.

  2. YujianYao-MSFT 4,286 Reputation points Microsoft Vendor
    2022-06-17T02:13:15.473+00:00

    Hi @Markus Andhoy ,

    According to this issue:

    Starting in Visual Studio 2015, this message may result from Windows virtual memory pressure caused by too many parallel build processes. In this case, the recommendation to use the /Zm option should be ignored unless you are using a #pragma hdrstop directive.

    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.

    In this case you could use /Zm to increase the limit. Alternatively, you could invest a lot of time in reducing the complexity of include files.

    You could also try:

    Project->Settings->c++ tab, there is an engineering option (O) below. Add**/Zm1000** or**/Zm2000** at the end of the parameter in the edit box, as long as it is a multiple.

    The number parameter is a scale factor with a default value of 100, which specifies the memory allocation as 50 MB. The maximum value is 2000. The following table shows how the numbers modify the memory allocation.

    212218-table.png

    Best regards,

    Elya


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. جلال عبدالله زيادة 91 Reputation points
    2022-06-20T07:22:03.64+00:00

    The number parameter is a scale factor with a default value of 100, which specifies the memory allocation as 50 MB. The maximum value is 2000. The following table shows how the numbers modify the memory allocation.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.