In this specific example my use case simplifies to this:

-File 'A' with unique ID's

-File 'B' is a list of possibly repeating ID's.

The output needs to be a count of how many times each ID in file 'A' occurs in file 'B'.

So to do this I just create a hash with keys being all the ID's from 'A', and value being a count of how many times it is seen.

File B is then streamed through to update the counters of the hash.

Now this works for me because the memory size, and my number of items, just happens to be a reasonable size for computers these days, falling somewhere between 4GB and 16GB as peak memory used.

I would be very interested in ideas people have for how to achieve this on a local PC without using much RAM, while also not just using disk in place of RAM. One way is to obviously load a subset of keys from A, then stream the file B to update counts for just those keys, and save the results. Then load the next lot of keys, and re-stream the entire file B, repeat until done. This is probably what I would do if I ran out of RAM. But while I have the RAM, I want to use it.

If both files were sorted, I could stream both at the same time, as I would know which ID's I pass. But in my case File 'A's sequence of ID's is important. So if I sorted A, I would have to reconstruct its order, and I don't see how sorting would be done without using just as much RAM.


In reply to Re^2: Perl memory limit - Windows64 strawberry perl by sectokia
in thread Perl memory limit - Windows64 strawberry perl by sectokia

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.