in reply to Re^6: Who's a thief? (No memory growth with magic goto)
in thread Who's a thief? -- the follow up
From perlsyn:
The goto-&NAME form is highly magical, and substitutes a call to the named subroutine for the currently running subroutine
Limbic~Region's post referenced a post by TimToady which will give the real skinny of how it works, but it does avoid the stack growth at the penalty of requiring the programmer to arrange for the algorithm to be tail-recursive.
You can use closures to provide yourself with one or more "stacks" if that is required. By controlling what gets stacked and when, even some non-tail recursive algorithms can benefit from reduced memory consumption and greater speed. It is especially useful for mutually recursive algorithms that need to share intermediate results.
That takes some effort, but if you have an inherently recursive algorithm that lends itself to that process, and a need for speed, then it can be worth it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^8: Who's a thief? (No memory growth with magic goto)
by dragonchild (Archbishop) on Jan 14, 2005 at 21:36 UTC | |
by BrowserUk (Patriarch) on Jan 14, 2005 at 21:46 UTC |