Generic const - a non-functional view

Dee Girl deegirl at noreply.com
Thu Jun 26 17:29:43 PDT 2008


Me Here Wrote:

> Simen Kjaeraas wrote:
> 
> > Me Here <p9e883002 at sneakemail.com> wrote:
> > > I know the above proves it, because I can monitor the memory usage and
> > > addresses.
> > > I used a very large string and the mutated a character in the middle of
> > > it. If the original string was mutated, the memory consumption of the
> > > process   would have to (breifly) double. It does not.
> > 
> > Could not the garbage collector theoretically be intelligent enough to see
> > that there's only one reference to the string, and thus not do CoW?
> > 
> > -- Simen
> 
> Perhaps you will find this a more convincing demonstration:
> 
>     [0] Perl> $s = 'the quick brown fox';;
>     [0] Perl> $r = \substr $s, 10, 5;;
>     [0] Perl> $$r = 'green';;
>     [0] Perl> print $s;;
>     the quick green fox

I stand corrected. As could your manners ^_^.

This is good example. Trick of taking a reference to result of substr is new to me. Very interesting even when I made $$r = "very long string" x 100 it still works. The number of characters can be different. How they do it?

Maybe now D is more better compared to Perl because in D you can not make aliased changes to string! Thanks for teaching me. Dee Girl



More information about the Digitalmars-d mailing list