From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,b0745a0b15631e1d X-Google-Attributes: gid111c93,public From: "Shana Tackett" Subject: Re: Maximum array size? Date: 1999/02/21 Message-ID: <7aps04$opv@bgtnsc01.worldnet.att.net>#1/1 X-Deja-AN: 446821862 References: <36C208BE.1D15@leland.Stanford.EDU> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: AT&T WorldNet Services Newsgroups: comp.os.linux.alpha It just so happens that 2^24 = 1Mb. This leads me to believe that the default stack size is 1Mb. Since other variables are also on the stack (some which you may not be aware of implicitly, e.g. argc, argv, etc.) you will always have < 1Mb for your local variables. Unless you are willing to right your code in assembler or patch the compiler to allocate more stack by default this is going to be a limitation. The second probably would not be wise since most applications do not use 1Mb in local variables. A better alternative is to dynamically allocate memory in the exact amounts needed using malloc or calloc. Refer to the man pages for a description. Here is a simple example. #include #include int main() { char *ptr; ptr = (char *) malloc(1<<24); if(ptr == NULL) printf("Failed\n"); else { printf("Sucess\n"); free(ptr); } return 0; } I have 96 Mb and this worked fine. For string variables, I prefer calloc since it sets the buffer to zero thus guaranteeing a NULL terminated string. This assumes you have at least one extra byte. Owen Peter Vajk wrote in message <36C208BE.1D15@leland.Stanford.EDU>... >Is there a maximum size for an array in C on an alpha? I have a program >that uses a character array that's about 27 MB, on an alpha with 128 MB >of RAM. I compile it under gcc, and when I run it I get a segmentation >fault immediately, even before it hits my first debug print statement. >Any suggestions? The limit seems to be a bit below 2^23 characters. >This bit of code produces a segmentation fault: > >---------------------------- >#include > >int main() >{ >char array[8384432]; >printf("Hello, world!\n"); >} >---------------------------- > >while this one runs normally: > >---------------------------- >#include > >int main() >{ >char array[8384433]; >printf("Hello, world!\n"); >} >---------------------------- > >Does this hold true for anyone else? And does anyone know how to get >around this limit, since there is certainly more than enough physical >memory to hold such an array. Thanks, > >Owen Vajk >ovajk*@leland.stanford.edu