c++ - VS2012 "Generating Code" slow with large hardcoded arrays -


we have tool generates class in header file generated hardcoded arrays. autogenerated inherited real implementation uses autogenerated values.

autogenerated example:

class mytestautogen {     std::vector<int> m_my_parameter1;     std::vector<int> m_my_parameter2;     ...  public:     mytestautogen()         {         setdefaultvaluefor_my_parameter1();         setdefaultvaluefor_my_parameter2();         ...     }      void setdefaultvaluefor_my_parameter1()     {         int tmp[] = {121,221,333,411,225,556,227,.......};         m_my_parameter1.assign(tmp, tmp + 65025);     }      void setdefaultvaluefor_my_parameter2()     {         int tmp[] = {333,444,333,987,327,16728,227,.......};         m_my_parameter2.assign(tmp, tmp + 65025);     }      ...  }; 

compiling takes lot of time , in output windows of vs can see hangs on "generating code" phase of compilation, finish compile after 15-30min unless compiler crashes stack overflow.

i have tried enable "multiprocessing compilation" , "parallel code generation" flags did not show improvements. disabling "whole program optimization" not option after application initialization should perform optimized possible.

my workaround issue modify autogenerated template save values in encoded binary string maybe data stored in text area instead of static area of library/executable. autogenerated code looks (the stringed hex values show):

class mytestautogen {     std::vector<int> m_my_parameter1;     std::vector<int> m_my_parameter2;     ...  public:     mytestautogen()         {         setdefaultvaluefor_my_parameter1();         setdefaultvaluefor_my_parameter2();         ...     }      void setdefaultvaluefor_my_parameter1()     {         std::string codeddefaultvalue = "\x079\0\0\0.......";         std::stringstream str(codeddefaultvalue);          int tmp;         (int = 0; < codeddefaultvalue.length() / sizeof(int); i++)         {             str.read((char*) &tmp, sizeof(int));             m_my_parameter1.push_back(tmp);         }     }      void setdefaultvaluefor_my_parameter2()     {         std::string codeddefaultvalue = "\x04d\x001.......";         std::stringstream str(codeddefaultvalue);          int tmp;         (int = 0; < codeddefaultvalue.length() / sizeof(int); i++)         {             str.read((char*) &tmp, sizeof(int));             m_my_parameter2.push_back(tmp);         }     }      ...  }; 

this compiles fast not readable (this file should not edited manually , not causally looked at).

is there better way without breaking cross-platform, without disabling optimizations , keeping header file?

it looks auto-generated numbers meant constant. expressed static const:

static const int tmp[] = {121,221,333,411,225,556,227,.......}; 

there vague rule "large" arrays, automatic storage (i.e. normal local variables) should not used; use static instead (alternatively, use dynamic allocation, not needed here). in addition, since numbers not changed, use const too.

btw it's pretty surprising breaking "rule" affects compilation time!


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -