Hi Perl Monks, The following code "Works" but I don't think it should. Can anyone explain why the code seems to work and does not give me random memory garbage? My program is eating up a lot of memory using this code and I am trying to find a way to store this data on disk, but using Tie or other methods doesn't seem to take the referenced array data into account..only the array references(being scalar and all that) - Anyway - here is some summarised code with the few specific lines detailed in full:
my %bigHash my @Arraybits do this a few times { @Arraybits = ["data","that","is","unique", "for","each","loop"]; my @tmparray = @Arraybits; until (We have done this a few times) { push @{ $bigHash {$Key} }, \@tmparray; #OR push @{ $bigHash {$Key} }, [@tmparray]; } @tmpxmlarray = []; undef (@tmpxmlarray); }
This code eats up memory really quickly. I put about 80,000 arrays into the hash this way. When I debug it I can see the full data set in the Hash and work on it whilsts the program is running However, if I tie the Hash to a DB_File or other db...I seem only able to store the array references on Disk..and my RAM still fills up, storing what I assume is all the array content. I would have thought that if I use undef, the data would be marked as feww in memory again...but al the array content is available...I just can't seem to get it out of RAM and onto disk. Any suggestions on an easy way to move this Hash of Arrays to disk including the array data and avoid eating up RAM?

In reply to Hash of Arrays - Pushing Array references and memory impacts question by alittlebitdifferent

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.