locked
Compiler is out of Heap Space at 4Gb RRS feed

  • Question

  • Hello,

    I'm currently trying to compile a cpp file using Visual Studio 2015 that uses the Eigen Matrix Library extensively. This Library is Header-Only and makes heavy use of templates. 

    When I want to compile the whole file I get the error "fatal error C1060: compiler is out of heap space". If I open the Task Manager during compilation I can see that "cl.exe" uses exactly 4Gb of memory before it crashes. There seems to be some hard limit of 4Gb that I cannot modify; In particular I've already tried to set the /Zm option to various values without effect and I'm creating a 64-bit application in Visual Studio.

    Is there some other way to increase the maximum heap size?

    Some more information: 

    I've managed to find the line (254) which causes the "heap buffer overflow". I.e. when I uncomment everything and including line 254 everything works. If I uncomment line 254 but comment all lines strictly greater than 254 I get error C1060. The funny thing is now that I can also comment lines 200-224 and keep line 254 uncommented and everything compiles. In other words I could lower the needed heap space by commenting lines 200-224 out and this allowed me to compile line 254 which was not possible before. 

    I hope I'm not the first one experiencing this issue.

    Raffael

    Monday, July 27, 2015 2:09 PM

All replies

  • Hi craffael,

    May I know what is the line (254)?  Is it a infinite recursion which cause the memory reach 4GB? So I guess you may have some code issue in your project.

    If all of your C++ code is OK, please check this doucment with possible solution.

    https://msdn.microsoft.com/en-us/library/yz7kx3y2.aspx

    Since you are using a third party library, please also try to ask this issue to the library writer, for example, the offical website.

    Best regards,

    Shu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 28, 2015 6:14 AM
  • Well, the compiler itself is 32 bit, so a 4 GB memory limit isn't really surprising.  That said, unless the templates are exceedingly complex, you shouldn't really be hitting that limit.  You might look to see if you can provide a simpler reproduction case and post it to Connect.
    Tuesday, July 28, 2015 7:27 AM
  • The described Problem is a general Problem of the VS Compiler if Templates are used very extensive. At work we had exactly the samle problem. We have a software module (DLL) that uses Templates very extensive and this piece of code is not able to be compiled using the VC compiler. For this module we use the Intel Compiler for Code generation since it is not possible to handle the Template stuff differently since most of this particular code will be generated automatically.

    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    Thursday, July 30, 2015 5:11 AM