65k array limit on G4 ?

sobrien140

Registered
I'm on a G4 powerbook. The following c code crashes with every gcc option I try. If the array size is dropped to 65100 the program runs fine.

Any advice?

main()
{
double x[65200];
printf("starting fit\n");
}
 
Just to clarify:

The first piece of code
Code:
main()
{
double x[65200];
printf("starting fit\n");
}

will try to put that whole array on your stack. So basically you've blown your stack and your program crashes.

What anarchie is telling you to do is allocate memory for your array so that it resides on the application heap, where more memory is available.
 
I guess, to make sure the problem is just with exhausting stack memory - can you allocate two arrays of 65100 doubles?
 
The default limit for the entire stack is 8192k. This can be discovered using the shell command 'ulimit -s' or modified using the C functions getrlimit()/setrlimit(). The limit for allocating memory using malloc() is bounded by the system's available memory and paging file. And yes, you can allocate two arrays of 65100 doubles using malloc.
 
I meant allocate them on the stack - putting 65100 doubles on the stack is fine, putting 65200 isn't.

To see whether the problem is stack space exhaustion, or some problem with trying to put 65200 doubles on the stack all at once; try putting 65100 doubles on the stack twice. If it is stack space exhaustion, the second declaration would still kill the program.
 
Back
Top