Generic const - a non-functional view

Me Here p9e883002 at sneakemail.com
Thu Jun 26 16:35:56 PDT 2008


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

Now the description.

1) Assign a string to the scalar $s
2) Take a reference $r to a portion of that scalar
3) Replace that portion in place by assigning through the reference.
4) Print the modified original string.

Besides which, I don't think I know this. I know I know it.

As for the GC deciding not to do COW, Your way off base here, in Perl at least.

b.

-- 




More information about the Digitalmars-d mailing list