Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Visual C++ long compile due to big struct

I'm running Visual C++ 2003 and am encountering very long (>1 minute) waits in the compile / Generating code stage of a build.

This is due to a large (120KB) single static structure that I'm including into my source code. The struct is simply made up of about five CStrings. Removing most of the lines from this struct array makes the build process only several seconds.

struct entry {
      unsigned      val;
      CString            a;
      CString            b;
      CString            c;
      CString            d;
      CString            e;
};

// Very large constant array here (~2000 lines)
const entry myclass::m_entries[] = {

{ 0 ,"str1","str2","str3","str4","str5"},
{ 0 ,"abc","str2","str3","str4","str5"},
{ 0 ,"str1","str2","defg","str4","str5"},
{ 0 ,"str1","asdf","str3","erwe","str5"},
...
{ 0 ,"12345","str2","str3","str4","str5"},
};

Why does the build process take so long when this single struct is included? Is there any compile option in the compiler that would correct this?

Lastly, is there a better way to incorporate a relatively large data set in the application? (each string entry is variable length, so the compile will be replacing each with string pointers).

Thanks for any help
0
chojan
Asked:
chojan
1 Solution
 
jkrCommented:
I don't really see a reason why to use a CString here - does using

struct entry {
      unsigned      val;
      char*            a;
      char*            b;
      char*            c;
      char*            d;
      char*            e;
};

speed up compilation?
0
 
AndyAinscowCommented:
If the strings are all up to a maximum length (eg all less than 10 chars) maybe you ought to consider having them as character arrays instead of CString variables.


Rather than at compile time if you had the contents as a text file and read it at run time?
0
 
chojanAuthor Commented:
Even though I was using CString as an aide for the rest of the use for this struct, the initialization using CStrings seems to have caused a significant burden when compared to the old standard char*.

Very glad that this made such a huge difference.

Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now