From: "Shana Tackett" <sltackett@worldnet.att.net>
Subject: Re: Maximum array size?
Date: 1999/02/21 [thread overview]
Message-ID: <7aps04$opv@bgtnsc01.worldnet.att.net> (raw)
In-Reply-To: 36C208BE.1D15@leland.Stanford.EDU
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 <stdio.h>
#include <stdlib.h>
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 <stdio.h>
>
>int main()
>{
>char array[8384432];
>printf("Hello, world!\n");
>}
>----------------------------
>
>while this one runs normally:
>
>----------------------------
>#include <stdio.h>
>
>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
next prev parent reply other threads:[~1999-02-21 5:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-02-10 5:00 Maximum array size? Owen Peter Vajk
1999-02-21 5:00 ` Shana Tackett [this message]
1999-02-21 5:00 ` Joachim Wesner
1999-02-21 5:00 ` Nobody
[not found] ` <7bqfk7$q53@bgtnsc03.worldnet.att.net>
1999-03-06 5:00 ` Ron Flory
1999-03-09 5:00 ` Shana Tackett
[not found] <rz7n22fx6kc.fsf@corton.inria.fr>
1999-02-22 5:00 ` Greg Lindahl
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox