I was wondering at what value the looping check will crash a proc?
Also, is it possible to change this value?
I thought I remembered someone asking this but I couldn't find it when I searched the forum.
ID:136978
Mar 21 2002, 2:41 pm
|
|
In response to Spuzzum
|
|
Yep, it's mainly for the little worms/snakes thing I'm working on. I move each segment of the worm by calling the function recursively until it reaches the end of the worm. I would use spawn() then call it recursively but then the worm doesn't move together and there is a delay between each segment moving.
Most worms shouldn't get over 100 segments but you never know. I ran into that problem when I was testing to see how large worms would look. |
In response to English
|
|
English wrote:
Yep, it's mainly for the little worms/snakes thing I'm working on. I move each segment of the worm by calling the function recursively until it reaches the end of the worm. I would use spawn() then call it recursively but then the worm doesn't move together and there is a delay between each segment moving. The answer here is to avoid recursion in this kind of case. To do that, you typically have the original calling function do a loop that keeps recalling the needed function. And you usually need to add an argument or two so you can keep track of which worm segment to work on next. I believe this is known as "keeping your own stack". We had to do this for DragonSnot because Leftley is insane and broke our perfectly good recursive trench algorithm. In this process I was shocked to discover that Windows (at least Win98) can only handle about 200 recursions. Most Unix systems handle 5x that or more. |
In response to Deadron
|
|
We had to do this for DragonSnot because Leftley is insane and broke our perfectly good recursive trench algorithm. Apparently I also broke your screenshots page--one of those used to be a simpler trench picture that I accidentally took in small icon mode, but now it seems that it's been replaced with a duplicate of one of the others. |
In response to Deadron
|
|
We had to do this for DragonSnot because Leftley is insane and broke our perfectly good recursive trench algorithm. Ah! Some very fine examples of Celtic sknotwork! |
In response to Lesbian Assassin
|
|
Lesbian Assassin wrote:
We had to do this for DragonSnot because Leftley is insane and broke our perfectly good recursive trench algorithm. Shouldn't that be "sknotwrkh"? =) |
In response to Deadron
|
|
The answer here is to avoid recursion in this kind of case. To do that, you typically have the original calling function do a loop that keeps recalling the needed function. And you usually need to add an argument or two so you can keep track of which worm segment to work on next. In this process I was shocked to discover that Windows (at least Win98) can only handle about 200 recursions. Most Unix systems handle 5x that or more. Really? That is strange, yet a good thing to know! I think I'll just make the change to a loop, should be simple enough. This is sort of a side question but still related. How exactly are function calls handled in memory? Our class has been learning about how various kinds of variables and arrays are stored and used but not functions. If this involves a long complicated answer then you don't need to answer it, I can hunt some online materials on the matter. |
In response to English
|
|
This is sort of a side question but still related. How exactly are function calls handled in memory? Our class has been learning about how various kinds of variables and arrays are stored and used but not functions. If this involves a long complicated answer then you don't need to answer it, I can hunt some online materials on the matter. Functions are stored directly in the executable -- making a function such as: char MyName() { rather than just using: int main() { is actually inefficient -- the OS actually has to take the time to dig through the machine code to find the function, run it, then jump back to the caller with the new memory stored. (Note -- I'm a bit rusty on actual arrays (the damn Advanced Placement program insists on using the STL vector class and String class), so that might not be fully right with regards to the character array.) That can be counteracted by using "inline" functions, but there's a time and a place for learning about those. =) |
loop_checks will generally crash the proc if it goes into 100 levels of deeper of iteration without having the condition change -- I think.
There's no way to customise it, but if there was, it should simply be the value of loop_checks.
I.e.
loop_checks = 500
would check up to 500 depth in iteration before yelling. I don't see a need for it, since I always design around infinite iterations whenever possible, but it would be useful for those who do need it. =)