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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gambler

    #1

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


    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(sort ByRot);

    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

  • Lasse Reichstein Nielsen

    #2
    Re: Array.sort return "out of memory" in IE and Mozilla

    gambler <gambler.1b1yy0 @mail.forum4des igners.com> writes:

    ....[color=blue]
    > so a sparsley populate array which enables me to locate a game using
    > the game number[/color]
    ....[color=blue]
    > games.sort();
    >
    > .. works but gives me a sort that I don't care about.[/color]

    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.
    [color=blue]
    > Worse than that it "re-indexes" the array and now the first element
    > is 0, the next element is 1, and so on.[/color]

    Yes, that is what "sort" does on sparse arrays.
    [color=blue]
    > I can't locate a game by the gamenumber without implementing a
    > search function.[/color]

    What did you want the sort function to do instead?
    [color=blue]
    > 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).[/color]

    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.
    [color=blue]
    > function sortByRot( gameA, gameB )
    > {
    > return gameA.rotNum1 - gameB.rotNum2;
    > }[/color]

    (maybe better named "compareByR ot")
    [color=blue]
    > which I was hoping would let me do:
    >
    > games.sort(sort ByRot);[/color]

    Sounds reasonable. It will still put all the defined elements before
    the undefined ones..

    [color=blue]
    > But in IE and Mozialla I get
    >
    > "An exception of type "Microsoft JScript runtime error: Out of memory'
    > was not handled." message.[/color]

    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?
    [color=blue]
    > Now I'm facing the unpleasant task of handling the sort myself.[/color]
    [color=blue]
    > Any help would be most welcome.[/color]

    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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Mick White

      #3
      Re: Array.sort return &quot;out of memory&quot; in IE and Mozilla

      gambler wrote:
      [color=blue]
      > let's say you have:
      >
      > var games = new Array();
      > games[gameNum] = new GAME(gameNum, rotNum1, rotNum2, ... );
      >
      > ([/color]

      I think you have to define a Constructor

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

      Something like that.

      or:

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

      Mick
      [color=blue]
      >
      > 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(sort ByRot);
      >
      > 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
      >[/color]

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Array.sort return &quot;out of memory&quot; in IE and Mozilla

        gambler wrote:
        [color=blue]
        > But in IE and Mozialla I get[/color]

        You mean _Mozilla_?
        [color=blue]
        > "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.[/color]

        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.
        [color=blue]
        > --
        > gambler[/color]

        Signatures are to be separated with a line containing DashDashSpaceNe wline.


        PointedEars

        Comment

        Working...