I want to initialize a global array of structure in a .cpp file. My array size is around 70000. Each structure will contain two pointers(of size 4 bytes each). .cpp File size after initialization becomes more than 1 MB. Apart from this big global array, I have few(10) more small variables (10-20 bytes).
When I compile this file in Visual Studio 2005, It is taking around 10 minutes to compile.
But when I breakdown this array of 70000 entry in to two arrays of 35000 entries each then compile time becomes 5 min(half of the original build time). But I due to project constraints,I don’t want to break global array in multiple small arrays. But we want to reduce the compile time also. Please let us know is there some compilation optimization trick or coding tricks is possible to bring down the compilation time.
Struct node
{
char* name;
int* ptr;
}
typedef Struct node NODE;
NODE invalidNode = {invalidNodeName,NULL};
NODE nodelist_10_nodeArray[] = {{"PETER",NULL},
invalidNode,
invalidNode,
invalidNode,
{"George",NULL}
{"SUNDAR",NULL}
invalidNode,
...,
...,
...,
},
Note: We have a lot of invalid entries.
You could set up the array with empty entries, then fill in the valid ones.
Or (disgusting hack which is probably not portable) you can assume that the individual arrays will occur consecutively in memory and just break them down anyway.
That is to say:
If you haven’t got array bounds checking on, this /should/ work. But I would include a very very very obvious comment in your source code, before, after and between each section, that this is a disgusting hack.
But almost any other solution is preferable, as that relies on implementation define behavior.