Generic const - a non-functional view

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 26 10:33:29 PDT 2008


"Dee Girl" wrote
> Steven Schveighoffer Wrote:
>> So, what it looks like is on assignment, the string is copied, and the
>> editing edits the string in-place.   But I can't really explain why it 
>> takes
>> 191MB to store x, where it only takes 100MB to store y.
>>
>> So I'd say perl does not have invariant strings.  'course, I'm not a perl
>> hacker, so I don't know if I did this correctly :)
>>
>> -Steve
>
> Hello! I think the first part of your message is correct. the second is 
> maybe mis guided. Walter is correct. Perl strings do not have mutable 
> chars. They can be think as similar to D strings. Your example with $x and 
> $y shows that.
>
> Perl can optimize copies sometimes. But it does not matter. Semantics is 
> all that matters. And Perl strings can not mutate individual chars ever. 
> Thanks, Dee Girl

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.

-Steve 





More information about the Digitalmars-d mailing list