That depends on how you defined/allocated your array. Most likely you defined it as an automatic variable in main(or any other function), which gets allocated in the stack, which is a limited resource. It's called a stack overflow.
int main(){
int thearray[SIZE];
sort(thearray);
return 0;
}
What you could do is to either define this array in global scope, which gets allocated on a different memory space, or allocate an array via calloc() function which goes to the heap which is very much plentiful.
#include <stdlib.h>
int first_array[SIZE];
int main(){
int *second_array = calloc(SIZE, sizeof(int));
return 0;
}
asrockw7
Junior Poster in Training
56 posts since Apr 2011
Reputation Points: 10
Solved Threads: 3
Stack is system defined as far as I know. It depends on what OS you are on and does not expand the same way your program heap does. If you're short on stack, then you're finished. Though you could expand it using some compiler options. Same way with the heap in that the OS defines an initial size for both, however the heap can be expanded by the OS.
As for their exact sizes, I don't know. As a rule of thumb though, be cautious with using stack as running out is catastrophic. If you would do the math though, if int is 4 byte and the threshold is at 2 million, you get 8 million bytes or 8,000 kb or 8mb. Mine in gcc is 4mb. As for the heap, well I would say just look at your RAM.(Not necessarily true as you are not allocated the whole pool at once, but since it can expand...)
asrockw7
Junior Poster in Training
56 posts since Apr 2011
Reputation Points: 10
Solved Threads: 3