Author Topic: Too big array size  (Read 7948 times)

Offline haxmando

  • Single posting newcomer
  • *
  • Posts: 2
Too big array size
« on: April 15, 2010, 10:55:16 pm »
I found out that when i declare a quite big array, for example int array[1000][100];
The program will crash, still it can handle smaller arrays. Could you say what is causing this?
I'm using Gnu gcc compiler.

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Too big array size
« Reply #1 on: April 15, 2010, 11:06:57 pm »
this is not a Code::Blocks question - your post will probably be locked.
However, here is an answer for you: if you are allocating an array inside a function (inside  {}), then memory on the Stack will be allocated (the Stack is a temporary memory allocated at function call, and freed at function exit).

The Stack has a limited capacity (it depends on the OS). So when you are allocating a very big array, you are using more memory than the Stack can handle.

And every Stack error leads to a program crash.

For the same reason, recursive functions are a very bad idea.

I suggest you to find a good book and / or web site for learning the programmation, this one for example:
http://www.cppreference.com/wiki/start

regards,

Sebastien