Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!bellcore!mrevox!lcuxlm!whuts!houxm!ihnp4!vax135!whb From: whb@vax135.UUCP Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: Question on large arrays in C Message-ID: <1762@vax135.UUCP> Date: Thu, 12-Feb-87 10:14:47 EST Article-I.D.: vax135.1762 Posted: Thu Feb 12 10:14:47 1987 Date-Received: Tue, 17-Feb-87 21:24:22 EST References: <1051@uwmacc.UUCP> Reply-To: whb@vax135.UUCP (Wilson H. Bent) Organization: AT&T Bell Labs, Holmdel, NJ Lines: 28 Keywords: C unix Xref: utgpu comp.lang.c:1066 comp.unix.questions:1069 Summary: Your auto arrays are too big! In article <1051@uwmacc.UUCP> jwp@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.