PDA

View Full Version : multi level arrays


GateKeeper
09-15-2002, 02:07 PM
I think I asked this question before, or something similar to it, however, I am looking to create a 3 dimensional array that will have a total of 6144 data elements in it. Is this going to be too much for most browsers to handle, and if it is, is there a way around it. The basic dimensions of the array are as follows;

X dimensions = 64 data elements
Y dimensions = 48 data elements
Z dimensions = 2 data elements

My primary concern is whether or not dial-up users are going to be crashed by such a large array. It is my hope to be able to use this array in conjunction with the trail marking script I have been working on to determine the best route from point A to point B based upon the type of terrain being traveled over. In other words I don't want the trail going directly over the highest mountain peaks, but rather, looking for reasonable passes around such peaks and (of course) following along the coastal regions instead of forcing the traveler to swim dozens (or hundreds as the case may be) of ocean. (Yes, this is for a Role Playing web site)

If anyone has any ideas on how to do this in an easier fashion without using CGI or some other sort of server side scripting, I am all ears.

GK

mordred
09-16-2002, 12:21 AM
Frankly, I don't know if there is a restriction on how large a multi-dimensional array in JS may be. Probably because I never ran into a similar problem like you did... ;)

But a dial-up connection doesn't necessarily determine the client's scripting capabilities: If you are on ADSL but use a browser that has a very old javascript engine implemented which does not understand arrays, then this engine will most likely produce errors. On the contrary, a user with dial-up and the most recent Mozilla build won't experience errors, but since the js code must be transmitted to the client, the might take a while to load... so he could get impatient and leave your site.

I would recommend to just give it a try and make extensive tests in a variety of browsers. Remember also that the sheer size of the array isn't the only problem, also the array manipulation functions might take (significantly?) longer...

beetle
09-16-2002, 01:09 AM
I agree/disagree with what mordred said.

It's about more than the browser's scripting abilities (although that's important) The only thing that gets sent to the broswer is the HTML. Period. The browser then uses system memory to do everything else from there. So, even though this example below will create lots of memory resident data var myArray = new Array()
for (var x=0; x<64; x++)
for (var y=0; y<48; y++)
for (var z=0; z<2; z++)
myArray[x][y][z] = x+y+z;It's only about 135 bytes. Most HTML tables structures take up much more filespace than this.

But, like others said before me, you should definitely test this, a 6000+ element array is pretty sizable, and far bigger than most.

GateKeeper
09-16-2002, 01:29 PM
Thanks a lot. That info definately helps. What I may end up doing is breaking things down into sub arrays that are called up as needed through a js library. Don't know if I can script that out yet, but I am working on it.

GK