By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

Array.sort return "out of memory" in IE and Mozilla

P: n/a

let's say you have:

var games = new Array();
games[gameNum] = new GAME(gameNum, rotNum1, rotNum2, ... );

(

so a sparsley populate array which enables me to locate a game usin
the game number without having to implement a "search" function on th
games array

games[4325] = new GAME(4325, 201, 202, 'Baseball', 'MLB', ... );

).

games.sort();

... works but gives me a sort that I don't care about. Worse than tha
it "re-indexes" the array and now the first element is 0, the nex
element is 1, and so on. I can't locate a game by the gamenumbe
without implementing a search function.

so here comes a sort function (for the first problem, I deal with th
renumbering by creating a temp array, copying things over, sorting th
temp array and bringing everything back in the original array. nast
business).

function sortByRot( gameA, gameB )
{
return gameA.rotNum1 - gameB.rotNum2;
}

which I was hoping would let me do:

games.sort(sortByRot);

But in IE and Mozialla I get

"An exception of type "Microsoft JScript runtime error: Out of memory
was not handled." message. Now I'm facing the unpleasant task o
handling the sort myself.

Any help would be most welcome.

Regards,
Gamble
-
gamble

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
gambler <ga************@mail.forum4designers.com> writes:

....
so a sparsley populate array which enables me to locate a game using
the game number .... games.sort();

.. works but gives me a sort that I don't care about.
What result do you want?

Sorting a sparse array will put all the defined elements before the
undefined ones, by design.

It will, obviously, change the order of elements, so they are (most
likely) no longer positioned where they originally were.
Worse than that it "re-indexes" the array and now the first element
is 0, the next element is 1, and so on.
Yes, that is what "sort" does on sparse arrays.
I can't locate a game by the gamenumber without implementing a
search function.
What did you want the sort function to do instead?
so here comes a sort function (for the first problem, I deal with the
renumbering by creating a temp array, copying things over, sorting the
temp array and bringing everything back in the original array. nasty
business).
Perhaps necessary, but hard to tell without knowing what you want.
Some times, it's enough to sort an array of indices, with an
appropriate comparison function.
function sortByRot( gameA, gameB )
{
return gameA.rotNum1 - gameB.rotNum2;
}
(maybe better named "compareByRot")
which I was hoping would let me do:

games.sort(sortByRot);
Sounds reasonable. It will still put all the defined elements before
the undefined ones..

But in IE and Mozialla I get

"An exception of type "Microsoft JScript runtime error: Out of memory'
was not handled." message.
It's unlikely that that specific error message was produced by Mozilla :)

How much memory do you have? How many elements are there in your sparse
array?
Now I'm facing the unpleasant task of handling the sort myself. Any help would be most welcome.


If you could show us the offending page, and say how you want the
data manipulated, then I'm sure we'll have a suggestion.

--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2

P: n/a
gambler wrote:
let's say you have:

var games = new Array();
games[gameNum] = new GAME(gameNum, rotNum1, rotNum2, ... );

(
I think you have to define a Constructor

function GAME(gameNum){
this.gameNum=gameNum;
for(a=1;a<arguments.length;a++){
this["rotNum"+a]=arguments[a]
}
}

Something like that.

or:

games[gameNum] = [gameNum, rotNum1, rotNum2, ... ]

Mick

so a sparsley populate array which enables me to locate a game using
the game number without having to implement a "search" function on the
games array

games[4325] = new GAME(4325, 201, 202, 'Baseball', 'MLB', ... );

).

games.sort();

.. works but gives me a sort that I don't care about. Worse than that
it "re-indexes" the array and now the first element is 0, the next
element is 1, and so on. I can't locate a game by the gamenumber
without implementing a search function.

so here comes a sort function (for the first problem, I deal with the
renumbering by creating a temp array, copying things over, sorting the
temp array and bringing everything back in the original array. nasty
business).

function sortByRot( gameA, gameB )
{
return gameA.rotNum1 - gameB.rotNum2;
}

which I was hoping would let me do:

games.sort(sortByRot);

But in IE and Mozialla I get

"An exception of type "Microsoft JScript runtime error: Out of memory'
was not handled." message. Now I'm facing the unpleasant task of
handling the sort myself.

Any help would be most welcome.

Regards,
Gambler

--
gambler

Jul 23 '05 #3

P: n/a
gambler wrote:
But in IE and Mozialla I get
You mean _Mozilla_?
"An exception of type "Microsoft JScript runtime error: Out of memory'
was not handled." message. Now I'm facing the unpleasant task of
handling the sort myself.

Any help would be most welcome.
This is an ActiveServer Pages error message, not a client-side one (which is
why it not only shows up in IE) and probably not related to scripting.

You should have posted the relevant snippets of your constructor code.
--
gambler


Signatures are to be separated with a line containing DashDashSpaceNewline.
PointedEars
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.