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

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.