If you look at it from the other direction, each value stored in the array only takes up about 32 bytes (even less, because the array itself has some overhead as well). I don't know much about perls internal memory structure, but every scalar has at least three slots, SV, PV and NV, for the string value, float value and integer value of said scalar. That's already 12 bytes taken up, plus another 4 bytes for the pointer from the array to that scalar (now at 16 bytes). The rest could be other overhead or simply more overhead from the scalars, which I didn't mention/know.

A matrix this huge might be better handled via C code as ints respective doubles, or a database, depending on how large your data will actually be.

If you really need a matrix this large, you should also consider what operations you want to perform on it, and whether a sequential storage in rows makes more sense - or whether floats hold enough precision to allow more complex operations such as multiplications/divisions without too much loss of precision...

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

In reply to Re: why does this array take up so much memory? by Corion
in thread why does this array take up so much memory? by Anonymous Monk

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.