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

largest array possible

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
> 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?


write it to a file...
--
H.Schampheleer
hu****@haps.be
www.haps.be
Nov 15 '05 #2

P: n/a
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" <me*****@hotmail.com> wrote in message
news:Xn*************************@194.117.133.134.. .
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

Nov 15 '05 #3

P: n/a
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,854,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]
- mv*@spam.guard.caspershouse.com

"Miha Markic" <miha at rthand com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <me*****@hotmail.com> wrote in message
news:Xn*************************@194.117.133.134.. .
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


Nov 15 '05 #4

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

Willy.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:et**************@tk2msftngp13.phx.gbl...
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,854,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]
- mv*@spam.guard.caspershouse.com

"Miha Markic" <miha at rthand com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <me*****@hotmail.com> wrote in message
news:Xn*************************@194.117.133.134.. .
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



Nov 15 '05 #5

P: n/a

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
Sure, but it returns "Length" cast to a long, so the max. value is still 2
Billion elements.


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
Nov 15 '05 #6

P: n/a
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" <me*****@hotmail.com> wrote in message
news:Xn*************************@194.117.133.134.. .
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

Nov 15 '05 #7

P: n/a
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.clear - 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.
Nov 15 '05 #8

P: n/a
tony collier wrote:
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?


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.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #9

P: n/a
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?
Nov 15 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.