diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-16 21:55:18 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-16 21:55:18 +0000 |
commit | 856f7ceee8cfa6203146ed626d3659ff3839fca9 (patch) | |
tree | 197d7d63f27facb03f0a45bb71b4eaf33ac14e96 /ace/SString.h | |
parent | 241771e4211608a5c21c153d0e7f17f5afd45641 (diff) | |
download | ATCD-856f7ceee8cfa6203146ed626d3659ff3839fca9.tar.gz |
Modified CString to not allocate 1 byte for a 0 length string. Instead, set the internal representation to the address of static class character null_string_.
Diffstat (limited to 'ace/SString.h')
-rw-r--r-- | ace/SString.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ace/SString.h b/ace/SString.h index 3e1bc8c462b..a3b5388f70e 100644 --- a/ace/SString.h +++ b/ace/SString.h @@ -31,9 +31,13 @@ class ACE_Export ACE_CString // ANSI/ISO C++ standard String class. Note that we need to use // this class since the ACE ACE_Map_Manager requires an object // that supports the operator== and operator!=. - // This class uses an ACE_Allocator to allocate memory + // This class uses an ACE_Allocator to allocate memory. // The user can make this a persistant class by providing an - // ACE_Allocator with a persistable memory pool + // ACE_Allocator with a persistable memory pool. + // NOTE: if an instance of this class is constructed from or assigned + // an empty string (with first element of '\0'), then it is _not_ + // allocated new space. Instead, its internal representation is set + // equal to a global empty string. { public: ACE_CString (ACE_Allocator *allocator = 0); @@ -70,6 +74,8 @@ public: const char *fast_rep (void) const; // Get at the underlying representation directly! + // _Don't_ even think about casting the result to (char *) and modifying it, + // if it has length 0! void operator += (const ACE_CString &); // Concat operator (copies memory). @@ -81,6 +87,7 @@ public: char operator[] (size_t index) const; // Return the <index'th> character in the string (doesn't perform // bounds checking). + // _Don't_ even think about modifying the result if it has length 0! int operator== (const ACE_CString &s) const; // Comparison operator (must match entire string). @@ -103,6 +110,9 @@ private: char *rep_; // Pointer to data. + + static char null_string_; + // Static null string. }; class ACE_Export ACE_SString |