mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2003
Posts: 4
D
Self-satisified door
OP Offline
Self-satisified door
D
Joined: Jul 2003
Posts: 4
alias counter { inc %counter.test | caller }
alias caller { if ( %counter.test < 1000 ) { counter } }

If I run /counter, %counter.test will only increase to 500. shocked

I'm not sure if this is hard coded to prevent infinite loops, or if it's just a bug.

I'm running 6.03 on Win2k Pro SP3.

Update: I had a friend try this on a 5.91 install and it only counted to 50. I'm thinking this limit is in there for a reason. I understand this isn't the most efficient way of performing this function, but it still peaks my interest.

Last edited by DemonWarp; 03/07/03 03:36 AM.

------------------------
#HardOCP on EFnet
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
In mIRC 6.00 it is 100, and I understood that 6.03 was 200.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Well to understand why there is a limit, you need to understand how recursion (which that is) works. Recursion works by using a stack. A stack is a data structure that works in such a way that the last item added to the stack is the first item removed. This allows you to back track through recursive steps after each one completes. The problem is, stacks are not infinite in size. Usually (with respect to recursion) they are a fixed size that can't be increased. Granted, 500 is a rather small limit, but the limit has to be set somewhere. The reason for it isn't so much to prevent infinite loops, infinite loops sometimes have a purpose, the reason is to prevent eating all available memory. As a stack grows, it needs more memory, if it were allowed to grow infinitely, then it would eat all the memory on your system. Why Khaled chose 500, I have no idea. The best suggestion I could make is let the user configure it. If you have 2GB of RAM and a 3Ghz processor, your machine can handle much more than 500 recursive steps, so there should be an option to raise it for you. But seeing as how Khaled hasn't added anything like that yet, and instead seems to just raise the limit after each release makes it seem that he doesn't want it user configurable.

Joined: Dec 2002
Posts: 17
KyD Offline
Pikka bird
Offline
Pikka bird
Joined: Dec 2002
Posts: 17
imho mircscripting should support infinite recursion like any decent programming language. if the stack size is a problem use a dynamically resizing stack.

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Umm, there is no such thing as infinite recursion. If you doubt that I'll make you a nice little C program that will keep recursing until it crashes. The runtime stack has a maximum size. Granted the size is pretty large, but it will crash if you exceed it. If you doubt what I say, here is an example from Microsoft that will lead to a stack overflow http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/vclrf_resetstkoflw.asp. No runtime stack allows for infinite recursion. Note that C code isn't exactly ANSI standard, it requires MSVC++ to compile since it uses MS's SEH (Structured Exception Handling).


Link Copied to Clipboard