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

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, 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, 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.