Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Memory issue with Hash

by nowise (Initiate)
on Dec 04, 2012 at 06:15 UTC ( #1007003=note: print w/ replies, xml ) Need Help??


in reply to Re: Memory issue with Hash
in thread Memory issue with Hash

In order to describe it more clearly , i have 1 example below, in which i have created 1 big hash-of-hash. Although i have put only 2 HOH inside %TV overhere ( just for clarity sake ), but in my code i have it 300 or more HOH ( while incrementing the key e.g jetsons1, jetsons2... ) in order to check the memory usage.

#!/usr/bin/perl5.8 use Proc::ProcessTable; #use Tie::File::AsHash;
my %hash= (); %TV = ( flintstones =>{ series => "flintstones", nights => [ qw(monday thursday friday) ], members => [ { name => "fred", role => " +lead", age => 36, }, { name => "wilma", role => " +wife", age => 31, }, { name => "pebbles", role => " +kid", age => 4, }, ], }, jetsons1 => { series => "jetsons", nights => [ qw(wednesday saturday) ], members => [ { name => "george", role => "l +ead", age => 41, }, { name => "jane", role => "w +ife", age => 39, }, { name => "elroy", role => "k +id", age => 9, }, ] },
sub memory_use { my $t = new Proc::ProcessTable; foreach my $got ( @{$t->table} ) { next if not $got->pid eq $$; return $got->size; } }
my $count = 10; my $key = 'test'; #tie %hash, 'Tie::File::AsHash', 'abc.csv', split => ':' or die "Pr +oblem tying %hash: $!"; foreach my $family (keys %TV) { $count++; my $record = ""; my $rec = $TV{$family}; my $key = $family . $rec->{series}; for $person ( @{ $rec->{members} } ) { $record .= $person->{name}."," . $person->{role}. "," . $person->{age} . "," . $rec->{series} . "," . $rec->{nights}[0]; } print "\n Key: $key \n"; print "\n Record: $record \n"; $hash{$key} = $record; if ( $count%10 == 0 ) { sleep(10 ); print "\n Record counter => [$count] \n"; print "\n Process Status:" . ( ( memory_use()/1024 )/1024 ) +."MB \n"; %hash = (); # if we comment it memory constant } } #----for 1----#


Comment on Re^2: Memory issue with Hash
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-08-22 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (144 votes), past polls