in reply to Re^2: perl ST sort performance issue for large file?
in thread perl ST sort performance issue for large file?
It would be far easier to advise you if you would post the code you are using.
Often, the most innocent looking pieces of code conceal things that unnecessarily consume memory.
For example, the convenient: my @array = <$fh>; uses twice as much memory as:
my @array; my $n = 0; $array[ $n++ ] = $_ while <$fh>;
Because in the first version, <$fh> first creates a list of the lines on the stack, which are then assigned to the array. For a breif time, you have two copies of the entire file in memory, with the obvious increase in total memory requirement.
In the second version, the array is populated directly thus avoiding that problem.
For the majority of uses, the first form is convenient and not a problem, but when you are butting your head against the capacity of your hardware, the change is worth the effort.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: perl ST sort performance issue for large file?
by rkshyam (Acolyte) on Apr 03, 2012 at 16:15 UTC |