Can anyone please let me know the exact difference between the regular string
class and the roguewave's rwcstring
class. The codes in my project extensively use the rwcstring
class. My doubt is if both handles and manipulates the strings then what is the exact difference between the two. Also why rwcstring class is considered more efficient than the regular string
class ?
RogueWave's RWCString
uses a technique known as lazy copying to improve its performance. Basically, this means that copying a string (be it through the copy constructor or the copy assignment operator) does not actually copy the contents of the string, but just keeps a pointer to the contents of the original string. The copy is only done when it is really needed (usually because the string contents are about to be modified). Since it is very usual for strings to be never modified, this provides a measurable performance improvement.
std::string
implementations are not explicitly forbidden from using this technique. In fact, some provisions in the standard were made thinking of this possible optimisation. The problem is that there are some ways to defeat this mechanism, such as taking a pointer to the contents of the string and changing them directly, without using the class mechanisms. This is the reason why it is unusual for std::string
to use lazy copying.
So, all in all, you may say that RWCString
is more efficient, but also less safe than the usual implementations of std::string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With