Generic const - a non-functional view

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 26 13:01:10 PDT 2008


"Dee Girl" wrote
> 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.

OK, I get what you are saying.  Immutability is not the important 
characteristic, it's value-semantics.  That still invalidates Walter's 
argument that immutability is essential to how perl strings 'just work'.

>
> 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!

I might care about whether perl decides to consume half my memory or not :) 
But technically I don't care since I don't use perl ;)

Thanks for the info!

-Steve 





More information about the Digitalmars-d mailing list