|
From: Per W. <pw...@ia...> - 2003-09-21 22:19:09
|
Half a million entries of int is 2MB.
The fist alternative isn't static - it isn't a global variable - but is
auto, i.e. stored on the stack. The stack isn't infinite, and should not
be used for huge allocations.
Because of the limitations in a 32-bit environment - max 4GB address space
- most OS limits the max stack size to a couple of MB, and try to keep as
large part of the address space available for dynamic allocation,
memory-mapped files, interprocess communication etc.
/Per W
On Sun, 21 Sep 2003, Alessandro Bugatti wrote:
> Why when I try to run the following program
>
> int main()
> {
> int a[1000000];
> system("PAUSE");
> return 0;
> }
>
> I have a fatal error during execution (it seems to happen when the array is over 500000)
> while the following program
>
> int main()
> {
> int *a;
> a=(int *)malloc(1000000);
> system("PAUSE");
> return 0;
> }
>
> works fine?
> In the first there is static allocation and in the second I use dynamic allocation, but the result should be the same (or not?)
> Thanks.
> Alessandro
|