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); }

In reply to Re: Re: Re: Anonymous or normal hashes? by duff
in thread Anonymous or normal hashes? by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.