in reply to Running out of memory while running this for loop
I am also running out of memory before the loop completes.
What is your idea of $aref in that loop that bombs off? Is it an integer, or an array reference? What it the result of adding 1 to an array reference? or 2 ? What happens to an array (or array reference) if you index it with the result of that addition?
my $aref = []; print $aref,"\n"; print $aref + 1,"\n"; print $aref + 2,"\n"; print "mem: ",qx{ps -o vsz= $$}; $aref[$aref +2] = "foo"; print "mem: ",qx{ps -o vsz= $$}; __END__ ARRAY(0xf5dba0) 16112545 16112546 mem: 28964 mem: 154844
By converting the hexadecimal address of $aref to integer - this is what happens if you add an integer to it - and using it then as an index, you extend @data and pre-allocate slots, each containing a NULL value. If the address of $aref is high enough, your program hits the memory limit of your machine.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Running out of memory while running this for loop
by Ppeoc (Beadle) on Nov 01, 2015 at 21:57 UTC | |
by AnomalousMonk (Archbishop) on Nov 01, 2015 at 22:45 UTC | |
by Ppeoc (Beadle) on Nov 02, 2015 at 01:53 UTC |