Boost logo

Boost :

From: Bohdan (warever_at_[hidden])
Date: 2002-10-03 08:26:49


   I'd like to propose immutable string class, i.e. string that has
immutable contents which can be pooled. IMHO immutable_string
is better candidate for various "name" properties than std::string.

cons:
    1) less space consuming when string type can contain multiple duplicate
values.
    2) faster copy, assign (string size is not significant).
    3) faster equality comparison (string size is not significant).
    4) hash code is calculated and stored, so std_ext::hash<
immutable_string >
       should be very fast.
cons:
    1) creation of immutable string is ~2 times slower than creation
       of ::std::string, but there are still a lot of optimizations to be
done.

Rationale:
      Most often string data belongs to one of following categories:

        1) value strings.
        2) name/symbol strings.

First category requires different string manipulations
( concatenation, substring, ...), whereas second requires
mainly creation, copy/assignment and equality-comparison.
First category requirements are fully covered by std::string.
It is also possible to use same class for second category,
but second category has less requirements hence can have
more effective implementation.
     Some languages (C#) implement such strings on language level.
Actually c/c++ compilers often have "string pooling" option,
but it works only for compile time "..." strings.

I've downloaded draft version to files section :
 http://groups.yahoo.com/group/boost/files/immutable_string/immutstr0.zip

some benchmarks for P4(1.6Gh):
----------------------------------------------------------------------------

---
type std::string :
                                                 bcc32(5.6)  gcc(3.1.1)  vc7
                                                 ---------------------------
---
fill array with different strings:               0.351       0.44
0.42
find tail element of array:                      0.16        0.401
0.471
comparing different size strings 60000000 times: 0.24        5.137
7.991
comparing equal size strings 60000000 times:     2.884       6.8
8.482
----------------------------------------------------------------------------
---
type immutable_string :
                                                 bcc32(5.6)  gcc(3.1.1)  vc7
                                                 ---------------------------
---
fill array with different strings:               0.661       0.721
1.051
find tail element of array:                      0.01        0.01
0.05
comparing different size strings 60000000 times: 0.221       0.12
0.972
comparing equal size strings 60000000 times:     0.2         0.11
0.961

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk