Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Memory issue with Hash

by nowise (Initiate)
on Dec 04, 2012 at 06:15 UTC ( [id://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----#

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found