|
Posted by Jürgen Exner on March 29, 2008, 11:23 am
Please log in for more thread options >Joost Diepenmaat a écrit :
>>
>>> Based on the fact that perl contains many memory leaks,
>>
>> It doesn't.
>
>I wrote a sample of code to illustrate the issue.
>
>The code create a 10 mega characters string. this is the only big data
>in this sample.
Which subsequently you copy a few times.
>Then, the main part of the code just modify this data; that mean that
>memory usage should (in my humble opinion) stay near of 10 or 20 (or 40)
>mega bytes.
>
>The main program does not manipulate directly the string, but makes
>functions aa and ab to manipulate this string. Those two functions aa
>and ab just make substitutions within the string.
No, they don't modify the string at all, they modify a _copy_ of the
original string.
>----- Script: ------------------------------------------
>
>
>sub aa($)
>{
> my ($d) = @_;
And here you create a copy of the original string.
> $d =~ s/x(.....)/$1y/g ;
> $d =~ s/x(.....)/$1z/g ;
> $d =~ s/x(.....)/$1a/g ;
> $d =~ s/x(.....)/$1b/g ;
> $d =~ s/x(.....)/$1c/g ;
> return $d;
You return that copy ...
>}
>
>
>my $c= 'x' x (1000*1000*10) ;
>$c .= "\x" ;
>print length($c) ."\n" ;
>my $v = qx( ps v $$ );
>print "$v\n" ;
>$c = aa($c);
...and you save that copy in $c, such that the memory cannot be reused.
The rest of the code seems to duplicate that action several times using
successively updated versions of the string as function argument, such
that successivly new copies of the string are created.
jue
|