in-place string reversal

Yu-Xi Lim yuxi at ece.gatech.edu
Tue Mar 28 10:03:47 EST 2006


Sathyaish wrote:
>> But what's got that to do with it? Strings are very mutable in C.
> 
> I realized after posting that I'd said something incorrect again. The
> concept of "mutability" itself is a high-level concept compared to C.
> Memory allocation for strings is expensive because of the way malloc()
> works to find a "best-fit" against a "first-fit" in traditional memory
> management systems. Because of the performance hit, high level
> languages and frameworks, such as the Common Type System of the .NET
> Framework for example, considers strings as immutable. That, unlike
> Python, doesn't however, make them impossible to modify in-place.
> 

I believe part of the reason for their immutability is so that they can 
be used as dictionary keys, which is a very common use.



More information about the Python-list mailing list