If you can break up your algorithm into chunks, one way around the "stop
script" problem can be to pause calculation for a few milliseconds and
resuming it.
Here's an example:
task: process N files in a folder
algorithm:
main()
{
process_100_files();
}
function process_100_files()
{
...
if (more_files_need_to_be_processed) {
setTimeout(process_100_files, 1);
}
}
I think it might be possible to do the same with timeout of 0
milliseconds, but not sure.. 1ms is not all that much anyway.
Hope this helps,
Konstantin
Preet Shihn wrote:
> Heyas!
>
> I am a semi-javascript newbie. I noticed that Javascript isn't really
> great with long running recursive methods or a long running while loop
> that can be memory intensive.
> I see the browser popup "A script on the page may be busy, or it may
> have stopped responding..... Stop the script or continue". I was
> wondering how people have dealt with this. An example of such a method
> that I was implementing is Flood Fill. Basically, fill a contoor with a
> specified colour.
>
> I know you can set a preference so that this message does not popup
> untill you run a bazillion line (whatever you set to), but that is not
> what I am looking for. I want a better performance.
>
> Other alternatives I can think of is wrting a custom xpcom object in C
> that does my computation.. or maybe a hidden java applet.
>
> It would be good to know how other people have dealt with this problem
> in general.
>
> Thanks,
> Preet
>
> p.s. In case anyone is interested, my flood fill method is a modified
> version of http://www.htmlgoodies.com/primers/jsp/article.php/3622321
> <http://www.htmlgoodies.com/primers/jsp/article.php/3622321>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Project_owners mailing list
> [email protected]
> http://mozdev.org/mailman/listinfo/project_owners
_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners