A colleague of mine claims that the implementation and especially the memory management of std::string
is inferior to that of the QString
in the Qt library. What aspects of the std::string
could this refer too?
Regarding memory management, QString
uses copy-on-write, which is now explicitly forbidden in the C++ standard library. But there is a reason for that. The copy-on-write idiom performs worse in multi-threaded environment as it requires synchronization. This article discusses the problems in more details.
Implementations of std::string
on the other hand typically use small-string-optimization (SSO) to avoid any dynamic memory allocation for small strings. That is the current state of the art for strings.
With the memory management, you'll have to decide what is better for your application. But one place where QString clearly shines in contrast to std::string, is the unicode support. QString stores an UTF-16 encoded string internally, while std::string is encoding agnostic. This often makes it much simpler to use QString rather then std::string when you have to deal with user-supplied multi-byte encoded strings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.