next up previous contents
Next: Operator Overload Choices Up: Design Trade-offs Previous: C vs C++ interface   Contents

Mutable vs Immutable Strings

The approach that Python, Java and other languages take with Strings is to make them immutable (unchangeable). This technique stores each unique string once in a data structure (typically a hash table) and represents Strings as references into this data structure. Under this approach, if a programmer sets x = "Hello" and y = "Hello", there is only one copy of "Hello" in memory and both x and y point to it.

The advantage of immutable strings are

There are also many disadvantages however:

My final take is that immutable strings offer some advantage and some disadvantages but tend to be more at home in a garbage-collected environment where the programmer has less control over how code executes.


next up previous contents
Next: Operator Overload Choices Up: Design Trade-offs Previous: C vs C++ interface   Contents
2007-05-05