Generic const - a non-functional view

Dee Girl deegirl at noreply.com
Thu Jun 26 10:48:13 PDT 2008


Steven Schveighoffer Wrote:

> I am not super-knowledgable about perl, but I understand the workings of 
> invariant strings and what they mean for memory usage.  The memory usage 
> exhibited by perl when copying one string to another suggests an entire copy 
> of the data, not just copying a reference.  If strings were immutable (like 
> they are in D or Java), then memory usage should not go up by 100MB when 
> simply assinging two variables to point to the same data.  It actually 
> appears to me that perl has mutable strings but only allows one reference to 
> the data at a time.  i.e. they are more like C++ std::strings (when not used 
> with references).
> 
> Perhaps you can explain how my example shows they are immutable?  Maybe I am 
> not getting something.

Perl has mix of reference counting with duplication and many optimization depending on code. It is mis guided to judge only by memory use. That is not relevant, just implementation detail. Tomorrow Perl is better, yesterday is bad. It is not relevant.

What is needed to look is semantics. Strings in Perl never alias, have strict value semantics. It is same as saying they have immutable characters because you can not distinguish.

You assign $y = $x. Two things could happen, a refcount is done or a full copy is done. You do not know. But you do not care! You care if changing one character in $x changes one character in $y. That never is happen. Which means semantically Perl strings are as good as strings of invariant characters. They never alias mutable data. This is the important thing. Thank you, Dee Girl



More information about the Digitalmars-d mailing list