develooper Front page | perl.perl5.porters | Postings from March 2003

Freeing hash table

Thread Next
From:
Alberto Manuel Brandao Simoes
Date:
March 12, 2003 00:16
Subject:
Freeing hash table
Message ID:
3E6E5858.9090105@alfarrabio.di.uminho.pt
Consider the following code:

my ($l,$i);
print "Reading data\n";
open (F, "</var/log/messages");
read F, $l, 2000; # 2k variable
                                                                                                    
my %t = ();
print "Filling hashtable\n";
for ($i=0; $i<50000; $i++) {
        $t{$i} = $l;
}
print "Done Filling\n";

print "Freeing\n";
undef %t;  # free it mode 1
#%t = ();    # free it mode 2
print "Done freeing\n";

Here we fill 100Mb of memory with an hash table. Then, we free it using 
the undef or the %t=(). Both methods take more than two minutes... if I 
use  for(...) { delete } it is really quick.

This was not my main question when developing this test program. The 
idea is to check how much we can free the memory and restart using it as 
efficiently as we were starting at the moment the script.

Regards,
  Alberto Simões



-- 
Departamento de Informática - Universidade do Minho - Portugal

"God is real, unless declared integer."




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About