I am writting a C++ program which checks if some words exist in Catalan, so I have a vector with the Catalan dictionary:
const vector<string> dict={"aaron","ababol","abac","abaca","abacallanada","abacallanava","abacas","abacial", ... ,"zum-zum","zur","zuric","zwitterio"};
The problem is that the dictionary has 107776 entries, so when I attempt to compile the file:
g++ -Wall file.cc -std=c++0x -o file.exe
it does nothing during a while and then Windows says that it isn’t responding and closes it.
How can I compile it? Is there a better way of storing this type of data (arrays, …)?
You may well have more luck with old-school built-in arrays:
This will generate a load of string literals and an array of pointers to them, which shouldn’t be too much of a strain for the compiler. This will also use no more memory than necessary, with little or no work at runtime.
Alternatively,
std::array<char const *>should be just as efficient, with more of a C++ look and feel.Your version also has to generate an enormous amount of code to build an
initializer_listfrom those, construct a string from each, and add each string to the vector. It will also require more than twice as much memory as each string literal needs to be copied into memory allocated at runtime, and then all those pointers need to be stored in another run-time allocated array.The disadvantage is that you may end up constructing a temporary string each time you read from the dictionary. If that’s a concern, then an array of
std::stringmight be a reasonable compromise.