Page 1 of 1

Question

Posted: Sat Mar 28, 2009 12:15 pm
by $oldier Of Ra
I know there is a limit of how many variables I can have in an array.
But is there a limit to how many variables I can have defined at the same time?

Posted: Sat Mar 28, 2009 2:19 pm
by Rookie One.pl
I'm sure there is. There's no way to find the value, though, other than getting as many vars in a script as possible and checking the number.

What do you need that for, anyway? I'd risk saying that if you run out of variables, you're a really bad coder.

Posted: Sat Mar 28, 2009 7:57 pm
by $oldier Of Ra
No reason actually, I was just wondering, I'm making lots of scripts (for my server) and I don't want to suddenly come to such an error.

EDIT: Ah I think I found the size. Someone had a problem with having too many entries in his array at tmt:

Code: Select all

The required variable stack size of 15226 exceeds the statically allocated variable stack of size 1024.
Increase SCRIPTTHREAD_VARSTACK_SIZE to at least 5226 and recompile.
I think the "1" in the first number is a typo (as is the case with many errors in mohaa). So I assume it's 5226 for the number of variables and 1024 per variable (= array). I think I won't ever have to worry about that then. :)

Posted: Tue Mar 31, 2009 8:48 pm
by Rookie One.pl
I think you misinterpreted the message a bit. This 5226 (or 15226, I wouldn't be so sure as to which one here is a typo) is actually the number of variables that the scripter put in his script, not a limit of the scripting engine. The developers were just trying to be make the message more meaningful to themselves during any debugging they might be doing by including that number.

Guessing by the constant name (SCRIPTTHREAD_VARSTACK_SIZE), I'd say that they implemented the scripting engine using a per-thread stack system with a fixed size of 4kB (1024 * 4 bytes; I bet that the stack is 32-bit and holds either integers, floats or pointers) per thread, regardless of the type of variables and their organization (i.e. 2 integer variables and a 2-element integer array both take up the same amount of space on the stack).

By the way, it's funny how all programmers have a habit of rounding constants to the nearest power of 2. I do it too. :)

Posted: Wed Apr 01, 2009 11:05 am
by $oldier Of Ra
Hmm, I see so if I understand correctly, it's quite impossible to "run out of" vars. 4 kb per thread is a lot!

Posted: Wed Apr 01, 2009 6:46 pm
by Rookie One.pl
Indeed it is a lot. I might be wrong about it being per thread, though, the fact that they named the constant SCRIPTTHREAD_VARSTACK_SIZE doesn't necessarily mean that. Those guys are known not to follow naming conventions closely.