Performance Considerations
The Essential Tools Module provides two implementations of
RWCString and
RWWString. While these different implementations have the same basic API, each features performance characteristics that are tuned to particular usage scenarios.
Table 5 shows the relationship between the two classes.
Table 5 – Comparison of Standard Strings with Copy-on-Write Strings
Classes | Description |
---|
| Based on the C++ Standard Library std::string or std::wstring respectively. Provide additional APIs for retrieving the underlying std::string or std::wstring instance. Take advantage of C++ Standard Library implementation-specific optimizations (e.g., Copy-on-Write, short-string optimizations, etc.) |
| Implement a Copy-on-Write pattern to prevent unnecessary duplication in use cases when strings are seldom or never modified. On platforms where the C++ Standard Library is not implemented using Copy-on-Write, provide: Improved per-object size Improved performance on assignment / copy construction Reduced memory usage for duplicated strings |
While these classes can be used directly and even mixed in the same application, it is generally recommended that you use the
RWCString and
RWWString aliases in your application. Whether
RWCString is an alias for
RWStandardCString or
RWCopyOnWriteCString (and similarly for
RWWString) is determined when building the Essential Tools Module Library. If the needs of your application change, you can rebuild SourcePro specifying a different implementation. See
Section 3.6.1.1, “RWCString and RWWString Implementation,” in
Installing and Building Your SourcePro Products for more details.
As a general rule of thumb, if
RWCString/
RWWString objects are being copied often but modified rarely,
RWCopyOnWriteCString/
RWCopyOnWriteWString will likely yield improved performance. Otherwise
RWStandardCString/
RWStandardWString should be preferred in order to take advantage of implementation-specific optimizations. Ultimately, the right choice is whichever implementation provides the best performance and system resource trade-offs for your application.