dimension of array

Recommended Posts

hi yesterday i discovered that the max dimension of an array is 25. after that i get some weird linking error(i'm using c++ with M\$VS 6) warning LNK4084: total image size -2146963456 exceeds max (268435456); image may not run (compiling went fine though) now i'm in search for a similar datatype with less restrictions

Share on other sites
That sounds weird... could you post your code?

Share on other sites
the line that produces the error is:
array[2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2]
these are 26 2's, if i remove one it works fine

Share on other sites
Er, have you considered how much storage space is in use there? That's probably the problem - 2^26 times the size of whatever it is you're storing o_O

What exactly are you trying to do?

Share on other sites
i'm trying to write a statistics program for the nba(national basketball assocation)
an easy example what the array does:
let's say a team has 10 players, only 5 of them can be on the court an once. if player1 is oncourt i give a variable called player1oncourt a '1', if he's offcourt it gets a '0'
the array then looks like this
array[player1oncourt][player2oncourt]..[player10oncourt] where 5 playerXoncourt are '1', 5 are '0'
whenever something happens to the game i add sth to the array
array[player1oncourt][player2oncourt]..[player10oncourt]
which *knows* who's oncourt and who's not

Share on other sites
multidimensional arrays are represented internally as normal arrays...

So.. You maybe getting to a size larger than max int... Let's say that internally a 32bit integer is the data type of array subscripts.. Thus, you can't have an array of a size larger than 2 ^ 32 = 4294967296...

Share on other sites
Quote:
 Original post by back2newbelfi'm trying to write a statistics program for the nba(national basketball assocation)an easy example what the array does:let's say a team has 10 players, only 5 of them can be on the court an once. if player1 is oncourt i give a variable called player1oncourt a '1', if he's offcourt it gets a '0'the array then looks like this array[player1oncourt][player2oncourt]..[player10oncourt] where 5 playerXoncourt are '1', 5 are '0'whenever something happens to the game i add sth to the arrayarray[player1oncourt][player2oncourt]..[player10oncourt] which *knows* who's oncourt and who's not

You've got things the wrong way around for sure. What you want is a single dimension array of 10 items (or however many it does need to be), and to represent whether player N is on or off course, set element N of the array to 0 or 1. The given array represents all the possible subsets of players, not simply all the players.

Share on other sites
int array[26];           // makes an array with 26 elementsarray[0] = some_integer; // writes to the first element

Share on other sites
as it is said that loop statements should not go beyond 3 levels,similarly is it that Arrays shuld not go beyond 3-4dimentions.Well I agree thatback2newbelf is doing it the wrong way and he should have only one array of 10.

Share on other sites
i'm not sure you guys really understand what i need.
let's say i want the score for lineup
player1, player3, player5, player7, player9

in my old code this would be
array[1][0][1][0][1][0][1][0][1][0]

how would i do this with array[10]??

Share on other sites
Quote:
 Original post by back2newbelfi'm not sure you guys really understand what i need.let's say i want the score for lineup player1, player3, player5, player7, player9in my old code this would bearray[1][0][1][0][1][0][1][0][1][0]how would i do this with array[10]??

ok, see

int array[10] allocates 10 elements that can be represented as one block of memory with the following indices:
{0,1,2,3,4,5,6,7,8,9}
int array[2][10] will allocate 2 times 10 elements:
[0]{0,1,2,3,4,5,6,7,8,9}
[1]{0,1,2,3,4,5,6,7,8,9}
ive put the first index in '[' and ']' and the second index into '{' and '}' now if you access array[1][5] you will access the field that is marked with 'x':
[0]{0,1,2,3,4,5,6,7,8,9}
[1]{0,1,2,3,4,x,6,7,8,9}
if you now take the third dimension you cant draw it onto a 2d plane (text) that easy, but you can do it with some tricks
for example:
int array[3][2][10] will allocate 3 times what we had before:
1st index is= 0
[0]{0,1,2,3,4,5,6,7,8,9}
[1]{0,1,2,3,4,5,6,7,8,9}

1st index is= 1
[0]{0,1,2,3,4,5,6,7,8,9}
[1]{0,1,2,3,4,5,6,7,8,9}

1st index is= 2
[0]{0,1,2,3,4,5,6,7,8,9}
[1]{0,1,2,3,4,5,6,7,8,9}

that could be interpreted as 3 different games where each team can get some points per round (2 teams) and they play 10 rounds.
hope you get it now, how arrays work
edit:typos

edit: if you really dont get how arrays work, use a map (you will need to "#include <map>") :
	std::map<std::string, bool> playersonfield;	std::string player1= "player1";	std::string player2= "player2";	//...	playersonfield[player1]= true;//=1	playersonfield["player1"]= false;//=0	if(playersonfield[player1])		std::cout << "Player1 Plays";	else		std::cout << "Player1 does NOT Play";

T2k

Share on other sites
let's do this step by step.
let's say we have a beachvolleyball team with 3 players, 2 can be on the court.
player1 and player2 are playing, they score
i do
array[player1][player2][player3]+=1;(which is array[1][1][0])

what do you do?

Share on other sites
Quote:
 Original post by back2newbelflet's do this step by step.let's say we have a beachvolleyball team with 3 players, 2 can be on the court.player1 and player2 are playing, they scorei do array[player1][player2][player3]+=1;(which is array[1][1][0])what do you do?

i would not use arrays, because they will not only store the important stuff, but will also waste memory... you are explicitely storing all other states, especially the score made when no players where playing and all other possible combinations

i would use the map and a bitset in this case (include <map> and <bitset>):
	std::bitset<3> playerconfig;	playerconfig[0]= 1; //player1 playing	playerconfig[1]= 1; //player2 playing	playerconfig[2]= 0; //player3 not playing	std::map<unsigned long, int> score;	score[playerconfig.to_ulong()]+=1;

that way you will not waste memory...

T2k

Share on other sites
Quote:
 Original post by back2newbelflet's do this step by step.let's say we have a beachvolleyball team with 3 players, 2 can be on the court.player1 and player2 are playing, they scorei do array[player1][player2][player3]+=1;(which is array[1][1][0])what do you do?

Not this.

I still don't understand your need. Are you trying to get teams statistics? Is yes then why not creating a team structure (with N pointers to some Player object) that will be used to index a std::map<>? T2k gave you an example of how a std::map<> works.

Your solution is probably the worst I could imagine. Adding one player double the size of the needed memory block, even if this player don't play often. It would be better to be more dynamic than this.

Regards,

Share on other sites
i have never used stl, so i have no idea about map or bitset.
also, let me tell you that there are 792 different lineups in basketball(one team with 12 players), that means i could just do an array like someArray[792] but i would not know which player is playing unless i make myself a huge list which would look like this:
player1, 2, 3, 4, 5 playing = array[1]
player1, 2, 3, 4, 6 playing = array[2]
...

this, i can't do, since i'd have to do this 792 times

Share on other sites
so eh, why not doing it more intelligent?

struct FOBAR{bool playerplaying[20];}; //20 players 0= not playing, 1= playing
FOBAR array[500]; //i really dont know what the max points in BB are and if they are going up by one, but its only a demonstration of the idea...

now you can do:
FOBAR currentconfig;
//set all players as you need etc...
int curpoint= 0;

//if someone makes a point you do:
array[curpoint]= currentconfig;
curpoint++;

still not optimal, especially because you can get games where the score moves in bigger and irregular steps, but noone stops you from storing the stuff in FOBAR...

T2k

Create an account

Register a new account

• Forum Statistics

• Total Topics
628375
• Total Posts
2982317

• 10
• 9
• 14
• 24
• 11