in reply to Re: Re: Anonymous or normal hashes?
in thread Anonymous or normal hashes?
You could test this yourself using top(1) or whatever the quivalent is on Windows if you're on that platform. There's also a module that will tell you how much memory your data structures are using, but I forget the name of it.
Simple tests of my own show that when I create a large hash, the program uses about 71M. When I pass it as a hash ref (sub foo { ...} foo(\%hash);), the program still uses about 71M. When I pass it as a hash (sub foo { ...} foo(%hash);), the program uses about 117M. When I pass it as a hash to a prototyped sub ((sub foo (\%) { ...} foo(%hash);), the program uses about 117M. Of course, I could have screwed up so test it yourself! :-)
Here's the program I used while I had top(1) running in another window. I just ran it 3 times with two of the three alternatives commented out each time and while it was sleeping I looked at the top window.
#!/usr/bin/perl print "creating hash\n"; $k = "aaaaaaaa"; for (0..1000000) { $hash{$k++} = $_ }; print "sleeping\n"; sleep (10); print "copying\n"; foo(\%hash); #bar(%hash); #baz(%hash); print "done"; exit; sub foo { print "sleeping in foo\n"; sleep(10); } sub bar (\%) { print "sleeping in bar\n"; sleep(10); } sub baz (%) { print "sleeping in baz\n"; sleep(10); }
|
|---|