in reply to Re: Re: Memory usage breakup
in thread Memory usage breakup
Tying down how much memory a given program will use, and what if any of that memory will be recycled, either internally by perl or back to the OS, is extremely complicated. (As well as highly OS / perl -V / individual perl build depenedant.)
For example, these 2 one-liners
P:\test>perl -e" { for( 1 .. 100_000 ) { $x[ $_ ] = ' ' x 1000; $x[ $_ ] = undef; } <STDIN>; } <STDIN>;"
In this first example, each element of the 100_000 element global array @x is allocated a 1000-byte value, which is then immediately 'freed' by undefing it. At the end of the loop, (the first prompt), 100+MB is allocated to the process. The space for 100_000 elements of 1000-bytes + the overhead for perls array and scalar structures. Even though only 1 element of the array has any space allocated (usable) at any given time.
P:\test>perl -e" { my @x; for( 1 .. 100_000 ) { $x[ $_ ] = ' ' x 1000; $x[ $_ ] = undef; } <STDIN>; } <STDIN>;"
The same program, except that the array is now locally scoped. When the first prompt is reached after the loop completes, again, 100+MB is being used, meaning that 99_999 elements of discarded (undef'd) space are lying around unusable and unused. However, once the second prompt is reached, ie. after the local scope in which @x was defined has exited, the memory used by the process (on my system) drops to 12MB.
With care and motivation, it is possible to force perl to re-use discarded memory, (and even return some of it to the OS under win32), but every attempt I've made to formulate a strategy for doing either, has fallen on stoney ground. I can do it on a case-by-case basis for many apps. I have begun to recognise some cases where I am reasonably sure that I can optimise the memory requirements through fairly simple steps, but inevitably, there are always exceptions to the rules of thumb I use.
Unfortunately, the exceptions are too common to make the rules of thumb viable for anything other than cases of extreme need.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Memory usage breakup
by Ven'Tatsu (Deacon) on May 01, 2004 at 15:38 UTC | |
by BrowserUk (Patriarch) on May 01, 2004 at 15:45 UTC | |
|
Re: Re: Re: Re: Memory usage breakup
by sgifford (Prior) on May 01, 2004 at 06:05 UTC |