The Directory Walker revisited
Dar Scott
dsc at swcp.com
Sat Sep 6 11:27:00 EDT 2003
On Saturday, September 6, 2003, at 06:19 AM, Wouter wrote:
> If I may ask just a little practical question to be able to completely
> understand your explanation :
>
> A folder "a" contains 3 folders "a1","b1","c1" and each of this
> folders contains another folder : "a1" contains folder "a2", folder
> "b1" contains folder "b2" and folder "c1" contains folder "c2".
>
> How many times your recursive handler is recursing?
I'll respond while David is sleeping.
The calls will be like this:
walkDir("/a")
walkDir("/a/a1")
walkDir("/a/a1/a2")
walkDir("/a/b1")
walkDir("/a/b1/b2")
walkDir("/a/c1")
walkDir("/a/c1/c2")
Total Calls = 7
Total Depth = 3
The depth of 3 is hit three times.
The last case of a depth of 3 is in the call walkDir("/a/c1/c2").
During this the stack looks like this:
Engine top routines.
The mouseUp handler data, perhaps.
The walkDir("/a") data.
The walkDir("/a/c1") data.
The walkDir("/a/c1/c2") data.
The data for current built-in command and expressions routines.
The cpu stack grows and shrinks as needed, so that the data for
walkDir("/a/c1") is in the space previously occupied by the data for
walkDir("/a/b1"). It is those walkDir() lines in the middle that
potentially could cause the cpu stack to grow excessively.
It is the depth that matters in the recursion limit, not the total
number of calls. A call to a simple handler might be in a repeat loop
and called many times, but it would not hit the recursion limit if it
does not the first time.
So...
> How many times your recursive handler is recursing?
I would use "recursing" as related to the depth, not the total number
of calls. Based on that, I would say the number of times is 3 or 2
depending on whether the first call is counted.
Dar Scott
More information about the use-livecode
mailing list