Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Re: Nested Calls, Recursion and MEMORY

by Anonymous Monk
on Dec 20, 2002 at 20:15 UTC ( #221503=note: print w/replies, xml ) Need Help??

in reply to Re: Nested Calls, Recursion and MEMORY
in thread Nested Calls, Recursion and MEMORY

Thank you MarkM, for your insights into the memory management of Perl. Very very very helpful.

So to recap what i have discovered..

*) Perl DOES do something different when a function calls itself, vs calling another function. If a function which is currently invoked, gets invoked by another or itself, it will allocate more memory, due to the fact that the current variables are already in use.
I didnt exhibit the extra memory allocations in my Non recursive nested calls, because no functions were ever invoked on themselves. Thus no need to allocate more memory.
It is not like C, where the functions local variables are pushed onto a stack, and it doest matter if it calls itself or another function. It would all be pushed and popped off correctly.

As my test code above demonstrated, running the "leaky" recurse function in a loop, does not accumulate more memory. It is reused. So , technically, its not a memory leak.

In my certain situation, where at the START of my program i do a deeply nested file glob, storing all filenames, then NEVER CALLING that function again, i end up with a program which runs on less memory, and the possibility of virtual memory disk swaps is great.

To get around this, i will create a seperate perl script which file globs to a text file. I will call this script via a system command, and load the text file it created. That way i have no recursion at the start of my main program, more memory and less disk swaps because of virtual memory.

So to continue my education, does anyone know or can point me to the sourcefile or document which technically explains how PERL deals with memory, global vars, local vars, etc? What technically happens when you do a local() or a my? I know C, C++/, many flavors of asm, so the more low level the better.

thank you again
  • Comment on Re: Re: Nested Calls, Recursion and MEMORY

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://221503]
[Corion]: Except that it doesn't work ...
[Lady_Aleena]: cPanel is a sponsor of meta::cpan?
[Lady_Aleena]: The default perl on the version of cPanel my web hosts uses is 5.8.8 which means I am dreadfully behind. I doubt perl 6 will hit my web host in my lifetime.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-05-29 09:44 GMT
Find Nodes?
    Voting Booth?