Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Large, Filled Arrays: What is Happening?

Reply
Thread Tools

Large, Filled Arrays: What is Happening?

 
 
Gene Wirchenko
Guest
Posts: n/a
 
      11-17-2011
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
 
Reply With Quote
 
 
 
 
Denis McMahon
Guest
Posts: n/a
 
      11-17-2011
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
 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      11-17-2011
On 17 Nov 2011 02:15:37 GMT, Denis McMahon <(E-Mail Removed)>
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
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      11-17-2011
On Wed, 16 Nov 2011 21:13:19 -0800, Gene Wirchenko <(E-Mail Removed)>
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
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      11-17-2011
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 <= .

Richard.
 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      11-17-2011
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
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      11-17-2011
On 17 Nov 2011 14:48:08 GMT, Denis McMahon <(E-Mail Removed)>
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
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      11-17-2011
On Thu, 17 Nov 2011 09:31:32 -0000, "Richard Cornford"
<(E-Mail Removed)> 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
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      11-17-2011
On Thu, 17 Nov 2011 06:34:48 -0800 (PST), Richard Cornford
<(E-Mail Removed)> 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 <= .


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
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      11-18-2011
In comp.lang.javascript message <26o8c7pumvbu8ki4tc2qn1eo24q1dvmefb@4ax.
com>, Wed, 16 Nov 2011 17:17:57, Gene Wirchenko <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem assigning selectedItem.Value to a dropdownlist filled with OnItemDataBound Antonio D'Ottavio ASP .Net 1 09-19-2005 09:41 AM
Howto:HTML template which needs to be filled with data from a data =?Utf-8?B?VmxhZHk=?= ASP .Net 4 10-05-2004 12:39 PM
RE: bind datagrid to dataset filled at runtime =?Utf-8?B?QmluIFNvbmcsIE1DUA==?= ASP .Net 0 04-08-2004 08:06 PM
Re: Listbox filled with Javascript does NOT maintain viewstate John Timney \(Microsoft MVP\) ASP .Net 0 08-29-2003 05:14 PM
Re: Listbox filled with Javascript does NOT maintain viewstate John Saunders ASP .Net 0 08-29-2003 05:08 PM



Advertisments