Simon Trew
unread,Jan 15, 2013, 3:21:45 AM1/15/13You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Excuse me for interuppting, I was an MVP in C++ many years ago but have been rather away doing other things. I have googled around but not had a definitive answer to my question.
My natural way to stick a character at the end of a string would be to do std:;string::push_back(c), where c is of type std::string::value_type (i.e. in practice a char or wchar_t), but with the Dinkumware standard library I have found this is incredibly slower (96ms on my 8 core for one push_back) than std::string::operator+=, and actually slightly quicker than that is std::string:;append(1, c);
I realise Mr Plauger knows what he is up to, and there may be a good reason for this but I can't see it. The template implementation of std:;string::push_back (unravelling the base templates etc) goes through insert(end(), c), and this is where the bottleneck is. += goes through append(c), and that is much much faster. I would have thought from the C++ spec that the two were equivalent, so I wonder if there is a technical reason why push_back has to do insert() rather than append(). P J Plauger usually has a very ostensible and correct reason for these things, but I can't find it on google groups etc, or a general search.
To remove doubt, this happens whether or not there are checked iterators or whether compiling for debug or release (with the standard settings for MSVC98).
Best wishes to you all.
Simon Trew.