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).
In reply to memory leak by Juba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |