inserting std::strings in to a std::map

Posted by PaulH on Stack Overflow See other posts from Stack Overflow or by PaulH
Published on 2010-03-16T13:05:42Z Indexed on 2010/03/16 13:16 UTC
Read the original article Hit count: 339

Filed under:

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

© Stack Overflow or respective owner

Related posts about c++