Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between a regular "string" class "rwcstring" class

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 ?

like image 824
Mariners Avatar asked Oct 21 '22 11:10

Mariners


1 Answers

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.

like image 155
Gorpik Avatar answered Oct 24 '22 05:10

Gorpik