I have a program that reads data from a file line-by-line. I would like to copy some substring of that line in to a map as below:
std::map< DWORD, std::string > my_map;
DWORD index; // populated with some data
char buffer[ 1024 ]; // populated with some data
char* element_begin; // points to some location in buffer
char* element_end; // points to some location in buffer > element_begin
my_map.insert( std::make_pair( index, std::string( element_begin, element_end ) ) );
This std::map<>::insert() operation takes a long time (It doubles the file parsing time). Is there a way to make this a less expensive operation?
Thanks,
PaulH
Edit: to be more specific, I want to know that I’m doing the minimum number of copy operations to get the data from the file in to the map.
To answer your supplementary question slightly. Try changing the map temporarily to a vector of strings, and then time it inserting a fixed string value into the vector For example:
That should give you a lower bound of what is possible regarding speed.
Also, you should time things with all optimisations turned on (if you are not already doing so). This can make a suprising difference to many Standard Library operations.