Chapter 2. WvString - dynamic character strings

Table of Contents
Introduction
WvString Examples

Introduction

WvString is an implementation of a simple and efficient printable-string class. It leaves out many of the notational conveniences provided by other string classes, because they waste too much CPU time and space.

It does the one thing really missing from char* strings, that is, dynamic buffer management.

When you copy one WvString to another, it does _not_ duplicate the buffer; it just creates another pointer to it. To really duplicate the buffer, call the unique() member function.

To change the contents of a WvString, you need to run its edit() member function, which executes unique() and then returns a char* pointer to the WvString contents.

The most annoying side-effect of this implementation is that if you construct a WvString from a char* buffer or static string, WvString won't duplicate it. Usually this is okay and much faster (for example, if you just want to print a static string). However, if you construct a WvString from a dynamic variable, changing the dynamic variable will change the WvString unless you run unique() or edit(). Worse still, deleting the dynamic variable will make WvString act unpredictably.

But it does cut out extra dynamic memory allocation for the most common cases, and it almost always avoids manual 'new' and 'delete' of string objects.