Boost logo

Boost Users :

Subject: [Boost-users] [container.string] why isn't memcpy used in the internals?
From: Adam Romanek (romanek.adam_at_[hidden])
Date: 2014-02-10 03:18:20


Hi!

Recently I've been trying to improve the performance of a code that
makes heavy use of std::string (lots of constructions and destructions).
My first thought was to use boost::container::string as it does not use
reference-counting and uses small-string optimization, so it should be a
perfect replacement for std::string when it comes to performance.

Right... But the problem is that switching to boost::container::string
only made things worse in the general case. I wrote "in the general
case" because when strings to be held are small and SSO may be applied
then boost::container::string outperforms std::string considerably.
However, in the general case constructing boost::container::string from
a C string is significantly slower than constructing std::string.

My investigation showed that std::string uses memcpy to copy the C
string into its buffer while boost::container::string does not. The
memcpy comes from std::char_traits::copy so maybe
boost::container::string could use it too? I guess the rest of
operations from std::char_traits (find, move, assign etc.) could be
utilized too as std::char_traits has been carefully crafted with
performance in mind.

Should I create a ticket for this issue?

Best regards,
Adam Romanek


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net