[bitlug] Re: Max size of array

  • From: Turuvanur Pavan-A20404 <pavan.tc@xxxxxxxxxxxx>
  • To: bitlug@xxxxxxxxxxxxx
  • Date: Thu, 3 Jun 2004 11:16:58 +0530

>  int main()
> {
>  int i;
>  int arr[100000];//8'0's: compiles, 5'0's: runs
>  scanf("%d",&i);
> }

The code's objective isnt very clear. You are scanning into i.
I think it should be &arr[i] with i initialized to a sane value.

I tested out the same program, the stack size limit being 8 MB(ulimit -a).
I could allocate a array of the following signature :

int arr[2*1024*1024 - 2*1024];

This comes upto 8MB - 2pages. This works fine for me.
This also looks logically ok, since there are other things that the
OS needs apart from my array on the stack, for which it wants two pages.
One page dint work. Check out this code :

#include <stdio.h>

#define SIZE 2*1024*1024
int main()
  int arr[SIZE-2*1024];
  int i = SIZE-2*1025;
  return 0;


Other related posts: