2011/05/14

Heap Memory Is Not Enough to Compile Spirit - Separate Definitions

VC's fatal error yields on compiling Spirit because its grammar is too large.

Fatal Error C1076

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

I had already set large heap-memory size to the compile option /Zm. Then, I moved all the grammar-rules definition from a constructor to several member functions and separated them to different translation unit. It may not be the best solution, but it resolves the heap memory problem.

// Before
class grammar_t ...
{
    ...

    grammar_t() ... {
       rule1 = ...
       rule2 = ...
       ...  // heap memory is over
    }

    rule_t  rule1;
    rule_t  rule2;
    ...
}
// After
class grammar_t ...
{
    ...

    grammar_t() ... {
       def_rule1();
       def_rule2();
       ...
    }
    void def_rule1();
    void def_rule2();
    ...

    rule_t  rule1;
    rule_t  rule2;
    ...
}

// in each translation unit (different source file)
void grammar_t::def_rule1() { rule1 = ...; }
// in each translation unit (different source file)
void grammar_t::def_rule2() { rule2 = ...; }
...

No comments:

How to set parameters to debugging program on Visual Studio 2019 with CMake

Solution: MSDN Sometimes the "Debug and Launch Settings for CMake" bottun is disabled. In this case, change to the target view. ...