Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Arrays in Java Script

0 views
Skip to first unread message

mike gardipee

unread,
May 25, 2001, 8:31:13 AM5/25/01
to
Does anyone know if there is an effiecient way to allocate memory for an
Array in javascript ? Take a look at the following.....

function CSomeConstructor()
{
this.m_Item1 = 0;
this.m_Item2 = 0;
this.m_Item3 = 0;
this.m_Item4 = 0;
}

var someArray = new Array();

for (var i=0; i < 100; i++)
{
someArray[ i ] = new CSomeConstructor();
}


Not only would I be allocating memory each time through the loop for
CSomeConstructor(), but the array has to grow each time as well, which I'm
guessing is analagous to something like using a CString and concatenating
it, which cause a realloc each time and is therefore very slow.

Is there something like a "grow-by" or anything else that can make this type
of process more efficient ? Any help is appreciated.

Thanks,

Mike Gardipee

Steve Fulton

unread,
May 25, 2001, 9:35:41 AM5/25/01
to
var someArray = new Array(100);

If the argument to the Array constructor is a single number, it is
interpreted as the new Array's length.

=-=-=
Steve
-=-=-

"mike gardipee" <mdgar...@doralsys.com> wrote in message
news:#RQSYaR5AHA.2052@tkmsftngp05...

Dave Anderson

unread,
May 25, 2001, 2:57:19 PM5/25/01
to
There is no need to allocate memory for an array in JScript. In fact, it's
not even possible. This, for example,

var someArray = new Array(100)

creates an array object and assigns 100 to its length property, but does not
allocate memory for any elements. That's because all JScript arrays are
sparse.

Here is some further information that appears to be stolen directly from the
second edition of David Flanagan's book (I strongly encourage you to buy his
latest - 3rd - edition, which is a great read and still very relevant after
3 years):


http://hrg.dhtp.kiae.ru/corvin/webref/jscript/ch08_05.htm#ch08-SECT2-AUTOID.
4

"mike gardipee" <mdgar...@doralsys.com> wrote in message
news:#RQSYaR5AHA.2052@tkmsftngp05...

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


mike gardipee

unread,
May 25, 2001, 5:20:52 PM5/25/01
to
Thanks for the input. I replied to Dave with the following, so I thought I'd
share it with everyone just in case .....


Here's a little more detail just in case......

I'm grabbing a recordset, with say 1000 records in it in my Remote Script.
Since you can not return an ADODB Recordset directly from Remote Script, I'm
building a java script equivelant of a RS, which ultimately means I've got
an array of objects. Here's the thing that's so aggrevating. It takes about
1 second to get the actual Recordset via my ATL component, and then it takes
like 30 seconds to build up the Java-Equivelant Recordset. I'm looking for a
way to speed that up.

Thanks again.

Mike Gardipee

"Dave Anderson" <GTSPXO...@spammotel.com> wrote in message
news:#j8mJyU5AHA.1332@tkmsftngp04...

0 new messages