largest array possible

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

    #1

    largest array possible

    i have created a 7-dimensional array [11,11,11,11,11, 11,11] which has 19.5
    million elements.

    when i try to create 8-dimensional array i get out of bounds system
    exception. does anyone know if this limitation is due to amount of memory
    in my pc or a limiation of c# language?

    thanks
  • H.Schampheleer

    #2
    Re: largest array possible

    > when i try to create 8-dimensional array i get out of bounds system[color=blue]
    > exception. does anyone know if this limitation is due to amount of memory
    > in my pc or a limiation of c# language?[/color]

    write it to a file...


    --
    H.Schampheleer
    hubert@haps.be



    Comment

    • Miha Markic

      #3
      Re: largest array possible

      Hi tony,

      I don't think that .net has such limitations.
      I would say that it is a memory issue.

      --
      Miha Markic - RightHand .NET consulting & software development
      miha at rthand com

      "tony collier" <melakka@hotmai l.com> wrote in message
      news:Xns943FF14 05FCA6tonycolli er@194.117.133. 134...[color=blue]
      > i have created a 7-dimensional array [11,11,11,11,11, 11,11] which has 19.5
      > million elements.
      >
      > when i try to create 8-dimensional array i get out of bounds system
      > exception. does anyone know if this limitation is due to amount of memory
      > in my pc or a limiation of c# language?
      >
      > thanks[/color]


      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: largest array possible

        Actually, I would guess there is a limit because of the limitation of
        the Length propery. In the 1.0 version of the framework, the Length
        property was a 32 bit integer, and because of that, you were limited to two
        billion or so elements.

        With the 1.1 version of the framework, you have the LongLength property,
        which exposes the length in a 64 bit integer, which means you have an upper
        limit of 9,223,372,036,8 54,775,808 elements (needless to say, a lot).

        However, what you are running into, like Miha said, is probably because
        of a memory constraint. To the original poster, do you really need to have
        that many elements in the array? What are you trying to do? Depending on
        the type of your elements, the memory alone for such an array could be
        restrictive in terms of performance.

        Hope this helps.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Miha Markic" <miha at rthand com> wrote in message
        news:%23Vc6TzAu DHA.2060@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > Hi tony,
        >
        > I don't think that .net has such limitations.
        > I would say that it is a memory issue.
        >
        > --
        > Miha Markic - RightHand .NET consulting & software development
        > miha at rthand com
        >
        > "tony collier" <melakka@hotmai l.com> wrote in message
        > news:Xns943FF14 05FCA6tonycolli er@194.117.133. 134...[color=green]
        > > i have created a 7-dimensional array [11,11,11,11,11, 11,11] which has[/color][/color]
        19.5[color=blue][color=green]
        > > million elements.
        > >
        > > when i try to create 8-dimensional array i get out of bounds system
        > > exception. does anyone know if this limitation is due to amount of[/color][/color]
        memory[color=blue][color=green]
        > > in my pc or a limiation of c# language?
        > >
        > > thanks[/color]
        >
        >[/color]


        Comment

        • Willy Denoyette [MVP]

          #5
          Re: largest array possible

          Sure, but it returns "Length" cast to a long, so the max. value is still 2
          Billion elements.

          Willy.

          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
          message news:etGYjZCuDH A.3116@tk2msftn gp13.phx.gbl...[color=blue]
          > Actually, I would guess there is a limit because of the limitation of
          > the Length propery. In the 1.0 version of the framework, the Length
          > property was a 32 bit integer, and because of that, you were limited to[/color]
          two[color=blue]
          > billion or so elements.
          >
          > With the 1.1 version of the framework, you have the LongLength[/color]
          property,[color=blue]
          > which exposes the length in a 64 bit integer, which means you have an[/color]
          upper[color=blue]
          > limit of 9,223,372,036,8 54,775,808 elements (needless to say, a lot).
          >
          > However, what you are running into, like Miha said, is probably[/color]
          because[color=blue]
          > of a memory constraint. To the original poster, do you really need to[/color]
          have[color=blue]
          > that many elements in the array? What are you trying to do? Depending on
          > the type of your elements, the memory alone for such an array could be
          > restrictive in terms of performance.
          >
          > Hope this helps.
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >
          > "Miha Markic" <miha at rthand com> wrote in message
          > news:%23Vc6TzAu DHA.2060@TK2MSF TNGP10.phx.gbl. ..[color=green]
          > > Hi tony,
          > >
          > > I don't think that .net has such limitations.
          > > I would say that it is a memory issue.
          > >
          > > --
          > > Miha Markic - RightHand .NET consulting & software development
          > > miha at rthand com
          > >
          > > "tony collier" <melakka@hotmai l.com> wrote in message
          > > news:Xns943FF14 05FCA6tonycolli er@194.117.133. 134...[color=darkred]
          > > > i have created a 7-dimensional array [11,11,11,11,11, 11,11] which has[/color][/color]
          > 19.5[color=green][color=darkred]
          > > > million elements.
          > > >
          > > > when i try to create 8-dimensional array i get out of bounds system
          > > > exception. does anyone know if this limitation is due to amount of[/color][/color]
          > memory[color=green][color=darkred]
          > > > in my pc or a limiation of c# language?
          > > >
          > > > thanks[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Miha Markic

            #6
            Re: largest array possible


            "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
            news:OU2ZEXFuDH A.3496@TK2MSFTN GP11.phx.gbl...[color=blue]
            > Sure, but it returns "Length" cast to a long, so the max. value is still 2
            > Billion elements.[/color]

            Yes, I am waiting for 128bit procesor so that I can put enough memory into
            my computer ;-)

            --
            Miha Markic - RightHand .NET consulting & development
            miha at rthand com


            Comment

            • Mountain Bikn' Guy

              #7
              Re: largest array possible

              I have created 9 dimensional arrays similar to that without any problems. (I
              used very dynamic jagged arrays.) I use this in a production environment and
              it is absolutely reliable. It does take a good bit of memory, but the code
              executes really fast and works really well. So I say, "Go for it!" if you
              really need this. If your dimensions are all hard coded, as they appear to
              be, you can probably find a better alternative, however.

              This looks like a situation where some good data structures-type design work
              could really pay off. If you care to share more details, I'll provide more
              comments.

              If you do move forward with the 7 dimen array, and if you are using it in
              code you plan to keep, put a lot of thought into making it OO and
              maintainable. If the array is as dynamic as ours, someone coming along after
              you won't be able to figure the code out unless it is very nicely designed.
              I wouldn't manipulate a 7 dimensional array directly in other code -- put it
              behind properties or methods.

              BTW, you can have 2 billion elements in each dimension.

              "tony collier" <melakka@hotmai l.com> wrote in message
              news:Xns943FF14 05FCA6tonycolli er@194.117.133. 134...[color=blue]
              > i have created a 7-dimensional array [11,11,11,11,11, 11,11] which has 19.5
              > million elements.
              >
              > when i try to create 8-dimensional array i get out of bounds system
              > exception. does anyone know if this limitation is due to amount of memory
              > in my pc or a limiation of c# language?
              >
              > thanks[/color]


              Comment

              • tony collier

                #8
                Re: largest array possible

                ok . thanks everyone for your advice so far. sorry to post several times
                the same message - i am getting used to my newsreader software.

                This is what i am trying to
                do and there is probably a much better way which this newbie hasn't read
                or thought about yet.

                i am getting prices from x number of suppliers who all quote me a
                different individual price for each of y items. no one supplier is always
                cheaper than the others.

                no. of suppliers: x (preferably unlimited)

                no. of items: y (again, preferably unlimited)

                i then calculate all the different combination of items from mixed
                suppliers. The formula to work out number of combinations =

                no.of supplier ^ (to the power of) no. of items.

                this requires creating an array of y dimensions with x elements per
                dimension to store all combinations

                as you will now understand , i have so far only been able to go up to x=
                11, and y=7 before running into memory constraints.

                items must be able to be added/deleted like in a cart until user
                checksout, so no running calculation can take place to try and crunch
                numbers as i go. this is why i can't see how array can be made any
                smaller.

                hope this all makes sense. any ideas to do this in a better way would be
                greatly appreciated.


                Incidentally, is there any way to initalize all elements in the array to
                zero in one fell swoop rather than looping through them? Someone has
                mentioned .system.array.c lear - does this work on uninitialized elements?
                someone else said that this was a feature not carried over from c++.

                Also, someone asked about some suppliers not having all items. So far i
                have covered this with another y=7,x=11 array where elements get flagged
                for any corresponding combination element that is zero.

                A database was mentioned although i know very very little about ado.net
                and sql so this would be a real chore for me to do it this way - surely
                reading and writing would be too slow for so many entries anyway?

                regards TC.

                Comment

                • Frank Oquendo

                  #9
                  Re: largest array possible

                  tony collier wrote:
                  [color=blue]
                  > A database was mentioned although i know very very little about
                  > ado.net and sql so this would be a real chore for me to do it this
                  > way - surely reading and writing would be too slow for so many
                  > entries anyway?[/color]

                  There's two ways to solve a problem: the fast way and the right way. If
                  you want to code an application that will not require any code
                  maintenance when the number of suppliers and/or items change, ADO.NET is
                  the way to go.

                  --
                  There are 10 kinds of people. Those who understand binary and those who
                  don't.


                  (Pull the pin to reply)


                  Comment

                  • tony collier

                    #10
                    Re: largest array possible

                    the suppliers will be fixed but the items will change on EVERY query as
                    they are searched for and then selected from an enormous list (which i
                    don't have access to) by clients thru a webform and and i can't get the
                    price for the items until i know what the client wants. I then
                    automatically go to the suppliers for prices and return the bestprice
                    combination to the user. For this reason i can't pre-populate a database.
                    I guess I could start with an empty database that populates with a client
                    request and then deletes entries once client closes session rather than
                    letting database grow and grow unneccesarily. Does this sound like a
                    better way than working with arrays?

                    Comment

                    Working...