|XP is just a number|
Thread::Queue memory issue with nested maps but not foreach loops...by jmmitc06 (Beadle)
|on Mar 03, 2012 at 02:21 UTC||Need Help??|
jmmitc06 has asked for the
wisdom of the Perl Monks concerning the following question:
I ran into some unusual perl behavior today at work and was wondering if anyone could explain why it occurs.
I was attempting to load a queue with a reasonable number of strings (200,000), with which I needed to do some work. I'm a big fan of using map in an anonymous context, so I loaded the queue inside of two nested map statements. Although this appeared to load the queue successfully and do the work I intended it to do, the amount of memory it used was very large, approximately 10,000MB with 1 thread. I then rewrote the code to load the queue inside of two nested foreach loops and only 800MB was used.
Can anyone explain this behavior, I know it has to do with how the queue is loaded and not with the work being done to the queued strings, for the following code snippets have the same behavior on my machine. The input is a flat file composed of .mol files.
Nested Maps (uses 10,000MB)
Nested Foreach (uses 800MB)
These are identical to the program I was working with except the doWork subroutine is replaced with something to actually do work. I don't mind the foreach version, I would like to know why the nested maps produces the behavior?
Any ideas would be appreciated.