Visual C++ long compile due to big struct

Posted on 2007-09-28
Last Modified: 2010-04-02
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
Question by:chojan
    LVL 86

    Accepted Solution

    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?
    LVL 43

    Expert Comment

    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?

    Author Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now