Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max on 3 dimensional array???

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
Hi,

Is there a max on defining a 3 dimensional array? For instance, is this too big of an integer array:

int array[99][101][400];

Does anyone know the max? The reason I ask is that I am getting a core dump near here and I can't think of any other reason why it might be happening.

Thanks.

Tyler

 
The only maximum is your available system memory. This is a fairly big structure: 99 * 101 * 400 * sizeof(int) {probably 4} = about 16MB.

If it's core dumping it's not solely because of the size of your data structure. Can you post the source code?
 
Hi,

Thanks for the reply.

I would love to post the entire thing but it is part of a business application that I can't post for security reasons.

But, I just did some testing. If I define the array in a simple main() program all by itself without setting any values, it is fine.

Code:
int main(void)
{
  int array[99][101][400];
  return 0;
}

But if I even try to set 1 value like so:

Code:
int main(void)
{
  int array[99][101][400];
  array[0][0][0] = 0;
  return 0;
}

It core dumps. That would seem to me to be a limit on memory somewhere. It is on a UNIX Sun 5.8 box. Any suggestions about what I should look for (or have our Unix admin look for?)

Thanks again.

-Tyler

 
Ahh... I see now. It looks like you're blowing some stack space by declaring a big structure like that locally. If you declare it in global scope or allocate the space dynamically you should be alright.
 
Hi,

That does the job! So, as long as I move it outside of main or outside of a function body then I should be ok, correct?

Thanks for the help.

-Tyler





 
You could also make it static, in addition to the methods Clairvoyant1332 suggested
Code:
int main(void)
{
  /* not on the stack, and its scope is limited to main */
  static int array[99][101][400];
  array[0][0][0] = 0;
  return 0;
}


--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top