in reply to Re: Out of memory.
in thread Out of memory.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Out of memory.
by BrowserUk (Patriarch) on Jul 23, 2003 at 11:24 UTC | |
I hate suggesting this, but it will probably make the out-of-memory problem go away with the least effort:) Change
to
That will filter out the vast majority of the lines produced by the dir /s before they get into perl. If you have WSH available, then you can use
Which probably isn't hugely more efficient than dir /s in terms of doing the calculation, but it will prevent the memory problem. You could also accumulate the directory sizes directly in perl
Which from my quick tests is much faster than shelling out, and seems to be quicker than using an FSO but it's difficult to measure as file system catching gets involved. You could also use any of the many File::Find modules to achieve the same effect. Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller | [reply] [d/l] [select] |
by Aristotle (Chancellor) on Jul 23, 2003 at 11:54 UTC | |
(Yes, File::Find is slower than hand rolled traversal. A heck of a lot less (and clearer) code, though, and still beats the dir /s approach by miles.) Makeshifts last the longest. | [reply] [d/l] |
by BrowserUk (Patriarch) on Jul 23, 2003 at 12:19 UTC | |
It wasn't in a void context. It was a scalar context :) That said, I'm still in two minds as to whether the 'map in a void context' problem is still a problem any more as (I believe) the main practical reason for not doing it was the inefficiency caused by building the return list only for it to be discarded. Since map now tests for context and doesn't bother building the list if in a void context, the reasons now seem esoteric/style related rather than practical. I agree that in most cases a for loop or modifier is better, but if you need to use a second modifier, map lends itself to the purpose. I wouldn't use it often, but I'm still undecided whether a blanket ban is called for. As for the File::Find and related calls. I have a (probably irrational) phobia about them, and it's not only to do with performance. I dislike their callback method of working, and their reliance upon global vars amongst other things. For example, the anonymous sub in your example is being called (many times) in a void context and the (unavoidable) return value is being discarded. How is this different from calling map in a void context? This really is "language lawyer" type stuff, but I seriously would appreciate your reaction/interpretation as I know you have made a point of studying many issues of this type. I'd also like to understand your (though that's not as bad on Win32) comment. How/why is this different for Win32 as compared to other OS's? I've racked my brains to see what you mean, but the significance escapes me? Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller | [reply] |
by Aristotle (Chancellor) on Jul 23, 2003 at 19:04 UTC | |
by BrowserUk (Patriarch) on Jul 23, 2003 at 19:39 UTC | |
| |
by blackadder (Hermit) on Jul 24, 2003 at 10:07 UTC | |
The first method did not work. Error The second method ignored sub directories. Would be usefull to me if I knew how get it to include Sub Dirs, no help in the documentaion. The last method failed to produce any out out. I tried printing $size and @files but got zilch display. So basically I am back to square root of 1. | [reply] [d/l] |
by blackadder (Hermit) on Jul 24, 2003 at 09:41 UTC | |
This did not work I got the following error; The OLE method worked but the values were not accurate because it ignored sub directories, would be useful if I knew how to get it to include sub dirs as well. I had a look in the documentation but there was not even a mention of GetFolder. Quick search on PM ,…nothing. This method seems to be the easiest for me, but only if I knew how to get the sub directories,…do I need to write a code the will recurs into sub directories?but then I am back to square 1! I am about to try out the final method… | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Jul 24, 2003 at 17:58 UTC | |
What can I say? So, all four methods will work, though they may not be "drop in" replacements for you original line of code, the effort required to make them so is minimal. Of course, this wouldn't be complete without answering the question that we are all dying to know the answer to:). Which is the fastest? Sorry, but despite my best efforts, I have been unable to arrive a consistant set of figures. The effects of multiple levels of caching, (disk caching, network redirector caching, perl caching stuff) mean that I can get different "winners" each time I re-run the tests. For reasons that I can't begin to explain, I can even get different results on the first run after a re-boot. Suffice it to say, once a network is involved (as opposed to my simulations within the same box), method 1 is likely to loose out badly simply because of the volumes of data being generated and discarded. This is true regardless of whether the discarding is done externally using the find filter, or internally to perl. Though saving perl from having to allocate large amounts of memory to store the huge lists generated is substantial of itself. I also encountered a occasional anomolies where the OLE code would bottle out with access denied errors, but they where not consistant, and immediatley after failure, running identical code but from a VBScript, produced no such errors, so it looks like there may be a problem somewhere in the Win32::OLE code. If I manage to tie down a reproducable testcase, I'll report this. I conclude that either of the perl solutions seems to be a good choice, as they both suffer the same limitations regarding the UNC path syntax and from what I can tell the difference in speed in minimal. The File::Find route is undoubtably cleaner code, so I would recommend Aristotles version over any of the three I offered. HTH. Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller | [reply] [d/l] [select] |
by blackadder (Hermit) on Jul 27, 2003 at 20:43 UTC | |