As Illuminatus points out, there are better ways to post your question (or perhaps, better questions you should be asking).

"Out of memory" failures should be pretty rare, in general, and only show up when there's some bug in the code, and/or some misunderstanding about the nature and quantity of your input data, so a few words to describe the data and what the code is supposed to do with it would be relevant.

A common cause of "Out of memory" failures is the use of a variable as an array index, when the value of the variable happens to be something unexpectedly (unintentionally) large -- here's the quickest/easiest way to get "Out of memory":

$ perl -le '$x=2**30; print $x; $a[$x]=0' 1073741824 Out of memory during array extend at -e line 1.
(Though conceivably some perl installs on some machines might succeed with that particular example.)

Another common cause is making multiple (unnecessary) copies of large files in memory -- e.g. doing stuff like:

@lines = <FILE>; # copy 1 $all = join("",@lines); # copy 2 for (@lines) { ($key,$val) = split " ", $_, 2; $hash{$key} = $val; # copy 3 }
If you know in advance that your script needs to access to more data than can fit in memory at a given time, then SQL access to a database is certainly a good way to work around that. DBM files are another option, if the data are structured as "key:value" tuples.

Whatever you are trying to accomplish, I would not recommend trying to game it so that your process tries to consume as much memory as possible without taking "too much" -- that approach only worked back in the old days of single-job systems (the original MS-DOS, DEC's old RT-11 are the only ones I recall), and nobody uses those anymore.

Assuming you know enough about your data and your task, you should be looking for a solution that runs within reasonable memory limits (or you should be putting more RAM on your machine until it's not a problem anymore).


In reply to Re: Out of Memory 2. by graff
in thread Out of Memory 2. by dneedles

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.