Question on large arrays in C

whb at vax135.UUCP whb at vax135.UUCP
Fri Feb 13 01:14:47 AEST 1987


In article <1051 at uwmacc.UUCP> jwp at uwmacc.UUCP (Jeffrey W Percival) writes:
>#define N 20480
>main()
>{
>	double x[N];
>	double y_1[N];
>	double y_2[N];
>	double y_3[N];
>	double y_4[N];
> [etc.]
>When I run it, I get "Segmentation violation".
>If I move the 5 array declarations up above main(),
>under the define statement, the program works OK.
>What is wrong with the program as listed above?
>	Jeff Percival ...!uwvax!uwmacc!sal70!jwp or ...!uwmacc!jwp

Five arrays times 20480 doubles per array times 8 bytes per array
	= 819.2 kbytes!
This is larger than the standard stack allocation (which is where
these arrays are being put).

Moving the delcarations out of main() puts them in the data
segment, which can get that much space with no problems.
Defining them in main() as static would do the same thing.
-- 
Wilson H. Bent, Jr.		... ihnp4!vax135!hoh-2!whb
AT&T - Bell Laboratories	(201) 949-1277
Disclaimer: My company has not authorized me to issue a disclaimer.



More information about the Comp.unix.questions mailing list