December 2001
Intermediate to advanced
304 pages
6h 25m
English
Difficulty: 6
In the third part of this miniseries, we examine the effect of references and iterators into a copy-on-write string. Can you spot the issues?
Consider the copy-on-write Optimized::String class from Item 14, but with two new functions: Length() and operator[]().
namespace Optimized { class StringBuf { public: StringBuf(); // start off empty ~StringBuf(); // delete the buffer void Reserve( size_t n ); // ensure len >= n char* buf; // allocated buffer size_t len; // length of buffer size_t used; // # chars actually used unsigned refs; // reference count private: // No copying... // StringBuf( const StringBuf& ); StringBuf& operator=( const StringBuf& ); }; class String { ...Read now
Unlock full access