Juba has asked for the wisdom of the Perl Monks concerning the following question:
I wrote a code to re arrange a two column file into a 4 column file. It turns out that when I use a large input the program crashes and spits the following message:
. *** malloc: vm_allocate(size=262144) failed with 3<br> *** malloc[591]: error: Can't allocate region<br> Out of memory!
The whole purpose is to randomize elements within each list of a huge list of lists and then pair within a list two by two elements.
My guess is that the problem is in the last loop of the following code. Could somebody please help me solving this problem? I ruan perl in MACOX 10.2.8 and , G4, 768 MB ram.
Thanks
@total = (); #this is an array of arrays @haplotypes=(); $currentPop = 0; $sampleSize={}; # This will hold the sample size for each population + while(<IN>) { chomp; if (/^(\-{0,1}\d+\t-{0,1}\d+)/) { $sampleSize{$currentPop}++; @temp = split; push @{$haplotypes{$currentPop}}, [@temp];<p> } elsif (/segsites: (\d+)/) { $currentPop++; push @total, $currentPop; } } foreach $_ (@total) { for($i = 0; $i < $sampleSize{$currentPop}; $i++){ $Rand=rand(int(@{$haplotypes{$_}})); $temp=splice (@{$haplotypes{$_}}, $Rand, 1); push @{$RandHapl{$_}}, $temp; } }
20040804 Janitored by Corion: Put code tags around code, reduced indentation
20040804 Janitored by davido: Put code tags around error message (necessary due to square brackets).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: memory leak
by BrowserUk (Patriarch) on Aug 04, 2004 at 15:45 UTC | |
by Juba (Initiate) on Aug 04, 2004 at 16:03 UTC | |
by BrowserUk (Patriarch) on Aug 04, 2004 at 16:13 UTC | |
|
Re: memory leak
by rsteinke (Scribe) on Aug 04, 2004 at 15:27 UTC | |
|
Re: memory leak
by VSarkiss (Monsignor) on Aug 04, 2004 at 15:24 UTC | |
|
Re: memory leak
by Juba (Initiate) on Aug 04, 2004 at 15:56 UTC |