Re: Memory issues



jm <jm@xxxxxxxxx> wrote:
Joost Diepenmaat a écrit :
jm <jm@xxxxxxxxx> writes:

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{1234}" ;
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
.



Relevant Pages

  • Re: Splitting a large string variable into lines <= 70 chars
    ... I kinda agree with you that perhaps the string search methods and functions like InStrRev and LastIndexOf will not be the fastest way. ... Wait till they grumble it's slow and then throw in a faster routine and your a hero again! ... All he'd done was reduce the number of iterations his code spent in the wait loops. ... Instead, do not modify the original string at all during the loop, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How do you remove all the symbols?
    ... The fact the msgbox shows "hidden message oxford st" shows the function is ... new changed string. ... If you are only using macros and want to change your original string you can ... Dim sOld As String ...
    (microsoft.public.excel.programming)
  • Re: strtok ( ) help
    ... >>> string between calls to strtok() its copy would no longer match. ... >> operation changed the original string between calls to strtokits ... > has to have a pointer into that string in all cases. ...
    (comp.lang.c)
  • Re: Comment on trim string function please
    ... If the char type on any machine ... How do you think the characters wound up in a string in the first ... original string: ...
    (comp.lang.c)
  • Re: splitting a long string into a list
    ... Agricultural subsidies; Foreign aid;Agriculture; Sustainable ... NOT modify the original string. ...
    (comp.lang.python)