Re: Perl and memory...
Amine wrote: > How can i 'force' Perl to return the used memory ? You cannot. This memory is actually free, you can still use it in your program, as you can see when you run "func" once again. Or, as your question partially suggests, use threads: ending a thread will release the memory back to OS. > When you will run this script , you will see that the > second call to func() does take a lot of time(much more > than the first call) , why ? It takes the same time for me (I've changed one million to five): #!/usr/bin/perl; use strict; use warnings; use Time::HiRes qw/time/; my $time = time; sub func { my @b; for (my $i=0;$i<500;$i++) { $b[$i] = 'Perl';} undef @b; print '@b memory returned..'; print $time - time, "sec\n"; } func; print $time - time, "sec\n"; func; print $time - time, "sec\n"; func; print $time - time, "sec\n"; print "end ...\n"; -- Serguei Trouchelle ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Perl and memory...
- Original Message - From: "rocku" To: "Amine" Cc: Sent: Friday, July 24, 2009 3:20 PM Subject: Re: Perl and memory... > To answer your first question, take a look at Perl's FAQ: > http://perldoc.perl.org/perlfaq3.html#How-can-I-free-an-array-or-hash-so-my-program-shrinks? > Hello, They wrote: "Memory allocated to global variables can be reused (within your program) by using undef()ing and/or delete()." I have 128 meg free memory on the system where i am testing , now even if i use a global variable and i run the script to fill the array it will take 60 meg bytes, and when i undef the array 18.5 meg bytes will return to the system, now how does Perl doesn't return more memory ? there is still more than 40 meg bytes remaining? And suppose we are using big arrays we will soon get out of memory, is it not a problem ? Regards, Amine. > Amine pisze: Regards, Amine. >> Hi all, >> >> Look at the following >> script: --- >> >> use Thread qw(:DEFAULT async yield); sub func >> { >> my @b; >> for ($i=0;$i<100;$i++) >> { $b[$i] = 'Perl';} >> ; >> undef @b; >> print '@b memory returned..'; >> ; >> } >> >> @param = (); >> my $t = Thread->new(\&func, @param); $result = $t->join; >> >> print "End of thread...\n"; >> ; >> >> -- >> >> On Windows click on Ctrl-Alt-del and click on Performance to look at the >> available memory. When you will run this script and the line print "End >> of thread...\n"; is executed all the memory used will be returned by >> Perl. >> >> But when the line 'undef @b' is executed , all the used memory is not >> returned. (please look on the Task manager)... >> So my question is: >> How can i 'force' Perl to return the used memory ? >> >> >> My second question is this: >> >> Look at the following script: >> >> --- >> >> sub func >> { >> my @b; >> for ($i=0;$i<100;$i++) >> { $b[$i] = 'Perl';} >> ; >> undef @b; >> print '@b memory returned..'; >> ; >> } >> >> func; >> func; >> >> print "end ...\n"; >> ; >> >> >> >> >> When you will run this script , you will see that the second call to >> func() does take a lot of time(much more than the first call) , why ? >> >> >> >> Regards, >> Amine. >> >> >> ___ >> Perl-Win32-Users mailing list >> Perl-Win32-Users@listserv.ActiveState.com >> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs >> > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Perl and memory...
To answer your first question, take a look at Perl's FAQ: http://perldoc.perl.org/perlfaq3.html#How-can-I-free-an-array-or-hash-so-my-program-shrinks? Amine pisze: > Hi all, > > Look at the following script: > --- > > use Thread qw(:DEFAULT async yield); > > sub func > { > my @b; > for ($i=0;$i<100;$i++) > { $b[$i] = 'Perl';} > ; > undef @b; > print '@b memory returned..'; > ; > } > > @param = (); > my $t = Thread->new(\&func, @param); > $result = $t->join; > > print "End of thread...\n"; > ; > > -- > > On Windows click on Ctrl-Alt-del and click on Performance to > look at the available memory. > > When you will run this script and the line > print "End of thread...\n"; > is executed all the memory used will be returned by > Perl. > > But when the line 'undef @b' is executed , all the used memory > is not returned. (please look on the Task manager)... > So my question is: > How can i 'force' Perl to return the used memory ? > > > My second question is this: > > Look at the following script: > > --- > > sub func > { > my @b; > for ($i=0;$i<100;$i++) > { $b[$i] = 'Perl';} > ; > undef @b; > print '@b memory returned..'; > ; > } > > func; > func; > > print "end ...\n"; > ; > > > > > When you will run this script , you will see that the > second call to func() does take a lot of time(much more > than the first call) , why ? > > > > Regards, > Amine. > > > > > > > > > > > > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Perl and memory...
Hi all, Look at the following script: --- use Thread qw(:DEFAULT async yield); sub func { my @b; for ($i=0;$i<100;$i++) { $b[$i] = 'Perl';} ; undef @b; print '@b memory returned..'; ; } @param = (); my $t = Thread->new(\&func, @param); $result = $t->join; print "End of thread...\n"; ; -- On Windows click on Ctrl-Alt-del and click on Performance to look at the available memory. When you will run this script and the line print "End of thread...\n"; is executed all the memory used will be returned by Perl. But when the line 'undef @b' is executed , all the used memory is not returned. (please look on the Task manager)... So my question is: How can i 'force' Perl to return the used memory ? My second question is this: Look at the following script: --- sub func { my @b; for ($i=0;$i<100;$i++) { $b[$i] = 'Perl';} ; undef @b; print '@b memory returned..'; ; } func; func; print "end ...\n"; ; When you will run this script , you will see that the second call to func() does take a lot of time(much more than the first call) , why ? Regards, Amine. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs