Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Since your post probably came from reading BrowserUk's question about Bidirectional lookup algorithm, let's put your theory to the test with the method he used:

use Devel::Size qw/total_size/; $h{$_} = 1 for "aaaaa".."zzzzz"; $elements_size += total_size $_ for %h; $hash_size = total_size \%h; print <<INFO; Total size of the contained elements: $elements_size Total size of the hash: $hash_size INFO __DATA__ Total size of the contained elements: 1223781728 Total size of the hash: 1167897536
It sure looks like I did something wrong. But since keys are constant strings (of fixed size), they probably take less space than a string in a scalar (scalar have all sorts of additional information, and a bit of extra space to avoid constant reallocation), so in the end I don't think I made any mistakes here. And I'm saying "probably" because I didn't check in the guts.

A lot of data in a hash sure takes a lot of memory, same goes for arrays because a lot of data will take a lot of memory unless it's properties allow for a very effective compression. If you only use pure perl, trying to avoid a hash because they are "bad" has very high probability of just being worse (hashes are an excellent compromise between algorythm complexity and memory consumption).


In reply to Re: RAM: It isn't free . . . by Eily
in thread RAM: It isn't free . . . by sundialsvc4

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found