Are you using the vector's reserve() method to precommit storage?
If not... when you know up front that you're expecting a lot of vector elements, you should use the vector's reserve() method to precommit storage. Otherwise every few push_back() calls the vector is going to have to resize its memory. This can have a high impact on speed.
Also, do you actually need to hold all entries in memory at once for your purpose?
Andy
@chipp
1 2
|
vector <string> s;
... sizeof (size_t) / sizeof (s) ...
|
- sizeof(size_t) = 4
- a vector is a struct with various members, including the size of the buffer, so whatever size it is, it's bigger than 4.
=> and in integer arithmatic 4/5 = 0 R 1
char* variables have a size of 4 bytes (in 32 bit case), but they are just pointers to the actual null terminating string, which can be any length (well, memory allowing)
And the size of std::string (Visual C++ 2008 release build) is 28 bytes. But this does not include the buffer.