简体   繁体   中英

Visual Studio C++ enum takes a long time to compile

I have a dll with an enum (and many other things)

enum class KIT_API VoxelTypes : uint16_t
{
  ... about a hundred entries ...
    ModellingClay_00 = 65406,
... more entries ...
    ModellingClay_128,
    COUNT
};

The value of element COUNT is 65535. I've been compiling this for over 45 minutes at the "Generating Code" stage. If I set ModellingClay_00 to 10000, it compiles in about 5-10 minutes. 15000 seems to take quite a bit longer, but did eventually compile.

Is there any reason an enum should take vastly longer to compile simply from changing the value it contains?

I'm pretty sure I've run afoul of some inner voodoo of Visual Studio set aside for my personal torment. Can anyone point out something obvious I've done, or even heard of this before?

Angew's analysis is correct.

There was a static array of VoxelTypes::COUNT elements. Each element was 88 bytes, for a total of 5,767,168 (5.5 Mb).

My work-around was to create an array of dynamic arrays instead of using a massive table of array initializers.

Old:

static Elements whoppingBigTable[] = {
    {Item1, 1, 1},
    {Item2, 2, 2},
};

New:

static Elements* whoppingBigTable[64];
for(int i = 0; i < 64; i++)
{
    whoppingBigTable = new Elements[1024];
}
AddElement({Item1, 1, 1});
AddElement({Item2, 2, 2});

Also had to add some math function to access the array elements. I assume that this is the fastest way to do it. It contains the definitions of my voxels, so I need to access it frequently. (I suppose I could also define separate arrays for each voxel property, and those arrays might be small enough to compile. That might be even faster than putting all properties into one giant array)

const Element& GetWhoppingElement(int index)
{
    int majorIndex = index / 1024;
    int minorIndex = index % 1024;
    return whoppingBigTable[majorIndex][minorIndex];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM