Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8381 > unrolled thread

Large, Filled Arrays: What is Happening?

Started byGene Wirchenko <genew@ocis.net>
First post2011-11-16 17:17 -0800
Last post2011-11-18 22:07 +0000
Articles 11 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  Large, Filled Arrays: What is Happening? Gene Wirchenko <genew@ocis.net> - 2011-11-16 17:17 -0800
    Re: Large, Filled Arrays: What is Happening? Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-17 02:15 +0000
      Re: Large, Filled Arrays: What is Happening? Gene Wirchenko <genew@ocis.net> - 2011-11-16 21:13 -0800
        Re: Large, Filled Arrays: What is Happening? Gene Wirchenko <genew@ocis.net> - 2011-11-16 21:27 -0800
          Re: Large, Filled Arrays: What is Happening? "Richard Cornford" <Richard@litotes.demon.co.uk> - 2011-11-17 09:31 +0000
            Re: Large, Filled Arrays: What is Happening? Richard Cornford <Richard@litotes.demon.co.uk> - 2011-11-17 06:34 -0800
              Re: Large, Filled Arrays: What is Happening? Gene Wirchenko <genew@ocis.net> - 2011-11-17 10:55 -0800
            Re: Large, Filled Arrays: What is Happening? Gene Wirchenko <genew@ocis.net> - 2011-11-17 10:38 -0800
          Re: Large, Filled Arrays: What is Happening? Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-17 14:48 +0000
            Re: Large, Filled Arrays: What is Happening? Gene Wirchenko <genew@ocis.net> - 2011-11-17 10:35 -0800
    Re: Large, Filled Arrays: What is Happening? Dr J R Stockton <reply1146@merlyn.demon.co.uk> - 2011-11-18 22:07 +0000

#8381 — Large, Filled Arrays: What is Happening?

FromGene Wirchenko <genew@ocis.net>
Date2011-11-16 17:17 -0800
SubjectLarge, Filled Arrays: What is Happening?
Message-ID<26o8c7pumvbu8ki4tc2qn1eo24q1dvmefb@4ax.com>
Dear JavaScripters:

     Were I to do
          alert("junk="+junk);
and junk had not been declared, it would be an error.  If junk had
been declared, the value would be displayed.  This might be undefined.

     With an array, the element need not have been assigned to to get
this behaviour.  Declaring the array means that
          alert("element="+theArray[i]);
for some i will not throw an error on the element being undefined.

     If I create a sparse array element, it is quick, as in:
          theArray=new Array();
          theArray[999999999]="way out there";

     With the above figured out -- if I am at all wrong in the above,
please tell me -- I thought that I would check performance on large,
filled-in arrays.

     The following code gives interesting results on my system.  I
have played around with initial values for Expand and how much it is
incremented at the end of the loop.

     When I try to get it to do the looping for expansion to
130,000,000, I get the confirmation box which I OK, I get the alert
box that it is starting, and THEN after a delay, I get the "Done"
text.  I do not get the alert box that the looping is complete nor the
one that outputs fLooping.  There is no error from my browser either.

     Why is what is happening happening?

***** Start of Code *****
<html>

<head>
  <title>try5.html</title>

<script type="text/javascript">
</script>

</head>

<body>

<script type="text/javascript">

theArray=new Array();
var OldMax=0;
var Expand=129000000;
var fLooping=true;
while (fLooping)
  {
  fLooping=confirm("Confirm do Expand="+Expand);
  if (fLooping)
    {
    alert("doing Expand="+Expand);
    for (var i=OldMax; i<Expand; i++)
      theArray[i]=i;
    alert("done Expand="+Expand);
    OldMax=Expand;
    Expand+=100000;
    }
  }
alert("fLooping="+fLooping);

</script>

Done

</body>

</html>
***** End of Code *****

Sincerely,

Gene Wirchenko

[toc] | [next] | [standalone]


#8382

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-11-17 02:15 +0000
Message-ID<4ec46e49$0$28627$a8266bb1@newsreader.readnews.com>
In reply to#8381
On Wed, 16 Nov 2011 17:17:57 -0800, Gene Wirchenko wrote:

>      When I try to get it to do the looping for expansion to
> 130,000,000, I get the confirmation box [1] which I OK, I get the alert 
box
> that it is starting [2], and THEN after a delay, I get the "Done" text 
[3].  I
> do not get the alert box that the looping is complete [???] nor the one 
that
> outputs fLooping [4].  There is no error from my browser either.

Looking just at the script element, and with a few markers added by 
myself:

<script type="text/javascript">
theArray=new Array();
var OldMax=0;
var Expand=129000000;
var fLooping=true;
while (fLooping)
  { // while (fLooping) ->
  fLooping=confirm("Confirm do Expand="+Expand); // [1]
  if (fLooping)
    { // if (fLooping) ->
    alert("doing Expand="+Expand); // [2]
    for (var i=OldMax; i<Expand; i++) theArray[i]=i;
    alert("done Expand="+Expand); // [3]
    OldMax=Expand;
    Expand+=100000;
    } // <- if (fLooping)
  } // <- while (fLooping)
alert("fLooping="+fLooping); // [4]
</script>

I'm having trouble working out which is the first alert that you don't 
get, where you say "I do not get the alert box that the looping is 
complete".

You describe 5 alerts in your explanation of what happens, but you only 
have 4 alerts. I would assume that after a successful expand for 
130,000,000, the next alert / dialog would be the confirm dialog for 
131,000,000, but that doesn't match your description of the alert box 
that you're expecting but don't receive.

If you are expecting the alert:

alert("fLooping="+fLooping);

to appear at the end of each loop, you need to include it *inside* the 
while loop, at the moment it will only trigger after the while loop has 
exited.

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#8383

FromGene Wirchenko <genew@ocis.net>
Date2011-11-16 21:13 -0800
Message-ID<4l59c7t96gcq3islvir8uvj0qkaiqborfh@4ax.com>
In reply to#8382
On 17 Nov 2011 02:15:37 GMT, Denis McMahon <denismfmcmahon@gmail.com>
wrote:

>On Wed, 16 Nov 2011 17:17:57 -0800, Gene Wirchenko wrote:
>
>>      When I try to get it to do the looping for expansion to
>> 130,000,000, I get the confirmation box [1] which I OK, I get the alert 
>box
>> that it is starting [2], and THEN after a delay, I get the "Done" text 
>[3].  I

     By "Done" text, I mean the "Done" after the </script>.

>> do not get the alert box that the looping is complete [???] nor the one 
>that

     That is the one that you labelled [3].

>> outputs fLooping [4].  There is no error from my browser either.
>
>Looking just at the script element, and with a few markers added by 
>myself:
>
><script type="text/javascript">
>theArray=new Array();
>var OldMax=0;
>var Expand=129000000;
>var fLooping=true;
>while (fLooping)
>  { // while (fLooping) ->
>  fLooping=confirm("Confirm do Expand="+Expand); // [1]
>  if (fLooping)
>    { // if (fLooping) ->
>    alert("doing Expand="+Expand); // [2]
>    for (var i=OldMax; i<Expand; i++) theArray[i]=i;
>    alert("done Expand="+Expand); // [3]
>    OldMax=Expand;
>    Expand+=100000;
>    } // <- if (fLooping)
>  } // <- while (fLooping)
>alert("fLooping="+fLooping); // [4]
></script>
>
>I'm having trouble working out which is the first alert that you don't 
>get, where you say "I do not get the alert box that the looping is 
>complete".

     That is [3].

>You describe 5 alerts in your explanation of what happens, but you only 
>have 4 alerts. I would assume that after a successful expand for 

     No, but I think that you confused the alert() you call [3] and
the "Done" after the </script>.  In retrospect, that was not the
clearest writing on my part.

>130,000,000, the next alert / dialog would be the confirm dialog for 
>131,000,000, but that doesn't match your description of the alert box 
>that you're expecting but don't receive.

     It does not get that far.  The script gets aborted AFAICS.

>If you are expecting the alert:
>
>alert("fLooping="+fLooping);
>
>to appear at the end of each loop, you need to include it *inside* the 
>while loop, at the moment it will only trigger after the while loop has 
>exited.

     I am not.  I put that there when I saw that the "Done" after the
</script> was getting output.  I did not think that fLooping would
have been changed -- since I only do it in the confirm() line -- but I
wanted to be sure.  It does not get executed at all AFAICS.

     Why is the script getting aborted and why is there no error
thrown?

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#8384

FromGene Wirchenko <genew@ocis.net>
Date2011-11-16 21:27 -0800
Message-ID<dl69c7drssmq6ec8qcr05rkh15immv699s@4ax.com>
In reply to#8383
On Wed, 16 Nov 2011 21:13:19 -0800, Gene Wirchenko <genew@ocis.net>
wrote:

[snip]

>     Why is the script getting aborted and why is there no error
>thrown?

     I have cut it down further.  The script consistently dies when
assigning to theArray[129954080] if all elements up to that point have
been assigned to.  In hexadecimal, the index is 0x7BEF120 which does
not appear significant in itself.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#8385

From"Richard Cornford" <Richard@litotes.demon.co.uk>
Date2011-11-17 09:31 +0000
Message-ID<FIGdnWDwgPzsSVnTnZ2dnUVZ8v-dnZ2d@giganews.com>
In reply to#8384
Gene Wirchenko wrote:
> On Wed, 16 Nov 2011 21:13:19 -0800, Gene Wirchenko wrote:
>
> [snip]
>
>>     Why is the script getting aborted and why is there no error
>>thrown?
>
>     I have cut it down further.  The script consistently dies
> when assigning to theArray[129954080] if all elements up to
> that point have been assigned to.  In hexadecimal, the index
> is 0x7BEF120 which does not appear significant in itself.

You haven't said which browsers you have tried this with. Browsers tend 
to have a 'safety' feature where they will not allow scripts to run 
indefinitely. IE, for example, has a limit on the number of consecutive 
statements it will execute before it puts up a dialog asking the user if 
they want to abort the script. Other browsers have been observed to put 
up a similar dialog if a single script runs for longer than a 
pre-determined period. It is also possible that some 
browsers/configurations of browsers could abort long running scripts 
without putting up any warnings. Getting consistent numbers prior to a 
script's being aborted on a single browsers/hardware combination may be 
a coincidence against a fixed time period or it may be just running into 
the browser's limit of consecutive statement execution.

Richard. 

[toc] | [prev] | [next] | [standalone]


#8387

FromRichard Cornford <Richard@litotes.demon.co.uk>
Date2011-11-17 06:34 -0800
Message-ID<dd2bd06b-4939-458b-9405-33c852542ae9@a16g2000yqk.googlegroups.com>
In reply to#8385
On Nov 17, 9:31 am, Richard Cornford wrote:
> Gene Wirchenko wrote:
>> On Wed, 16 Nov 2011 21:13:19 -0800, Gene Wirchenko wrote:
>
>>>  Why is the script getting aborted and why is there no error
>>>thrown?
>
>>     I have cut it down further.  The script consistently dies
>> when assigning to theArray[129954080] if all elements up to
>> that point have been assigned to.  In hexadecimal, the index
>> is 0x7BEF120 which does not appear significant in itself.
>
> You haven't said which browsers you have tried this with. Browsers
> tend to have a 'safety' feature where they will not allow scripts
> to run indefinitely. IE, for example, has a limit on the number of
> consecutive statements it will execute before it puts up a dialog
> asking the user if they want to abort the script. Other browsers
> have been observed to put up a similar dialog if a single script
> runs for longer than a pre-determined period. It is also possible
> that some browsers/configurations of browsers could abort long
> running scripts without putting up any warnings. Getting consistent
> numbers prior to a script's being aborted on a single
> browsers/hardware combination may be a coincidence against a fixed
> time period or it may be just running into the browser's limit of
> consecutive statement execution.

In IE 9 the problem is an "out of memory" error that can be seen if
you open the 'developer tools' (F12) and look at the Script tab.
Apparently IE no longer throws javascript exceptions when it
encounters out of memory errors (it did in version <= 8).

Richard.

[toc] | [prev] | [next] | [standalone]


#8391

FromGene Wirchenko <genew@ocis.net>
Date2011-11-17 10:55 -0800
Message-ID<9alac75luiqojifufu6tttfbah8b6epm6u@4ax.com>
In reply to#8387
On Thu, 17 Nov 2011 06:34:48 -0800 (PST), Richard Cornford
<Richard@litotes.demon.co.uk> wrote:

[snip]

>In IE 9 the problem is an "out of memory" error that can be seen if
>you open the 'developer tools' (F12) and look at the Script tab.

     I found that, and I had to rerun the script to get the error
while the tool was open.  It then stated out of memory in line 1. The
error is not in line 1.

>Apparently IE no longer throws javascript exceptions when it
>encounters out of memory errors (it did in version <= 8).

     More experimenting: I tried a try...catch block around the loop.
That caught an error: 0x800A0007, "Out of memory".  Subsequent
iterations apparently ran fine with no abort and no error.  How, if
out of memory, I do not know.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#8390

FromGene Wirchenko <genew@ocis.net>
Date2011-11-17 10:38 -0800
Message-ID<m0lac7d65pspj5o998smg7751gd974dhcr@4ax.com>
In reply to#8385
On Thu, 17 Nov 2011 09:31:32 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:

>Gene Wirchenko wrote:
>> On Wed, 16 Nov 2011 21:13:19 -0800, Gene Wirchenko wrote:
>>
>> [snip]
>>
>>>     Why is the script getting aborted and why is there no error
>>>thrown?
>>
>>     I have cut it down further.  The script consistently dies
>> when assigning to theArray[129954080] if all elements up to
>> that point have been assigned to.  In hexadecimal, the index
>> is 0x7BEF120 which does not appear significant in itself.
>
>You haven't said which browsers you have tried this with. Browsers tend 

     Sorry.  Internet Explorer 9.0.8112.16421 under Windows 7.

>to have a 'safety' feature where they will not allow scripts to run 
>indefinitely. IE, for example, has a limit on the number of consecutive 
>statements it will execute before it puts up a dialog asking the user if 
>they want to abort the script. Other browsers have been observed to put 

     I am not getting that.  And there would be variability on the
index number.

>up a similar dialog if a single script runs for longer than a 
>pre-determined period. It is also possible that some 
>browsers/configurations of browsers could abort long running scripts 
>without putting up any warnings. Getting consistent numbers prior to a 
>script's being aborted on a single browsers/hardware combination may be 
>a coincidence against a fixed time period or it may be just running into 
>the browser's limit of consecutive statement execution.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#8388

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-11-17 14:48 +0000
Message-ID<4ec51ea8$0$28505$a8266bb1@newsreader.readnews.com>
In reply to#8384
On Wed, 16 Nov 2011 21:27:43 -0800, Gene Wirchenko wrote:

> I have cut it down further.  The script consistently dies when
> assigning to theArray[129954080] if all elements up to that point have
> been assigned to.  In hexadecimal, the index is 0x7BEF120 which does not
> appear significant in itself.

Perhaps it represents a specific amount of ram?

Although I can break javascript by assigning a large enough array, this 
doesn't seem to be a catchable error. eg:

var a = new Array(),i=0;
try {
while(1) a[i++] = 0;
}
catch(e) {
document.write(e.description);
}

seems to use cpu for a while and then just stop, without outputting 
anything.

Rgds

Denis McMahon


Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#8389

FromGene Wirchenko <genew@ocis.net>
Date2011-11-17 10:35 -0800
Message-ID<gskac7tdp42cm63k41pju0iiaafqnu2213@4ax.com>
In reply to#8388
On 17 Nov 2011 14:48:08 GMT, Denis McMahon <denismfmcmahon@gmail.com>
wrote:

>On Wed, 16 Nov 2011 21:27:43 -0800, Gene Wirchenko wrote:
>
>> I have cut it down further.  The script consistently dies when
>> assigning to theArray[129954080] if all elements up to that point have
>> been assigned to.  In hexadecimal, the index is 0x7BEF120 which does not
>> appear significant in itself.
>
>Perhaps it represents a specific amount of ram?

     Apparently.

>Although I can break javascript by assigning a large enough array, this 
>doesn't seem to be a catchable error. eg:
>
>var a = new Array(),i=0;
>try {
>while(1) a[i++] = 0;
>}
>catch(e) {
>document.write(e.description);
>}
>
>seems to use cpu for a while and then just stop, without outputting 
>anything.

     At some point, the script is simply aborted, and page rendering
continues past that point.

     Well, it was a test of the limits, and an error message would
have been nice.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#8417

FromDr J R Stockton <reply1146@merlyn.demon.co.uk>
Date2011-11-18 22:07 +0000
Message-ID<OedMulHLctxOFwaC@invalid.uk.co.demon.merlyn.invalid>
In reply to#8381
In comp.lang.javascript message <26o8c7pumvbu8ki4tc2qn1eo24q1dvmefb@4ax.
com>, Wed, 16 Nov 2011 17:17:57, Gene Wirchenko <genew@ocis.net> posted:

>
>     When I try to get it to do the looping for expansion to
>130,000,000, I get the confirmation box which I OK, I get the alert
>box that it is starting, and THEN after a delay, I get the "Done"
>text.  I do not get the alert box that the looping is complete nor the
>one that outputs fLooping.  There is no error from my browser either.
>
>     Why is what is happening happening?


You need to say which browser you are using, and what version of it.
You need to say what debugging / error-reporting features are on and
visible.

You need either to say which OS and version you are using, or to explain
that it does not matter.

In this case you should say how much memory you have, or to explain that
it does not matter.

And, if you have any date/time problems, you need to say what Time Zone
the computer is set for, and whether that location uses, and is in,
Summer Time.  Don't be in Israel, if avoidable.

I don't think it is necessarily fair to say that the best browser is
ABBIE,

-- 
 (c) John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Turnpike v6.05   MIME.
   Web  <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.

                ABBIE is an acronym, probably new.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web