PDA

View Full Version : Override stack overflow?


xferior
08-15-2002, 08:38 AM
Is it possible to override the stack overflow in javascript or at least allocate more memory to the stack? I'm writing a program that assigns random numbers as coefficients to sets of variables, multiplies them through with thye existing coefficients, checks for equality, and repeats with different coefficients if all items are not equal. Obviously, a significant amount of looping occurs when there are several items, and the stack usually overflows with even slightly complex calculations. Any ideas for how to do this?

brothercake
08-15-2002, 09:48 AM
You can't get past a stack overload except to re-write the code; there are usually more efficient ways of doing most things, so show us what you're working with

RadarBob
08-15-2002, 02:18 PM
Again, depending on how you write it, you might try setting objects, variables to null each time you're done with them - but I don't have hi hopes for that. Things get destroyed, alledgedly, when exiting a function. But I've not read anything that suggests javascript has "garbage collection."

If you've written a recursive function, then I don't have any ideas.

Oh, If you're on a Macinosh with OS 9.x or earlier just go into the "info" dialog box for your browser and allocate more memory.

nolachrymose
08-15-2002, 03:46 PM
But I've not read anything that suggests javascript has "garbage collection."

It does. Now you have read it somewhere. ;)

Happy coding! :)

BrainJar
08-15-2002, 03:49 PM
It's hard to tell what the problem may be without seeing the code or the exact error message. But, if you're using recursion you can try reducing the number of local variables in the functions being called (so each call takes less memory) and removing tail recursion if possible.

You can also wrap code in try-catch blocks to keep the script from stopping when the error occurs.

mordred
08-16-2002, 12:20 AM
Instead of doing recursive functions, you could try repeating them with setInterval() (or was it setTimeout()? I don't remember), that should do the job without incurring the stack overflow.

xferior
08-16-2002, 06:37 AM
Well, setTimeout does work in this case, but it increases the calculation rate incredibly (100x or so), making the program very slow and virtually unusable for complex equations. If i could clear the stack overflow, OR somehow repeat the function if the stack overflows (if(stack.overFlow) or something like that????), then I would be all set.

xferior
08-16-2002, 06:38 AM
At any rate, the program can be used at http://www.xferior.com/balance.html and the source file for the jscript is at http://www.xferior.com/scripts/secondbalance.js. Thanks again to everyone who is contributing!