"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":
(Though conceivably some perl installs on some machines might succeed with that particular example.)$ perl -le '$x=2**30; print $x; $a[$x]=0' 1073741824 Out of memory during array extend at -e line 1.
Another common cause is making multiple (unnecessary) copies of large files in memory -- e.g. doing stuff like:
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.@lines = <FILE>; # copy 1 $all = join("",@lines); # copy 2 for (@lines) { ($key,$val) = split " ", $_, 2; $hash{$key} = $val; # copy 3 }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |