Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!seismo!mimsy!chris From: chris@mimsy.UUCP Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: Question on large arrays in C Message-ID: <5389@mimsy.UUCP> Date: Wed, 11-Feb-87 23:49:50 EST Article-I.D.: mimsy.5389 Posted: Wed Feb 11 23:49:50 1987 Date-Received: Thu, 12-Feb-87 23:30:26 EST References: <1051@uwmacc.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 38 Keywords: C unix Xref: utgpu comp.lang.c:987 comp.unix.questions:991 Summary: resource limit: stacksize 512K In article <1051@uwmacc.UUCP> jwp@uwmacc.UUCP (Jeffrey W Percival) writes: >I am running 4.3BSD on a MicroVax II. ... with array declarations that require 20480*5*8 = 819200 bytes. >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? Nothing. This is a `feature' of a large virtual address space with demand paging. The system cannot tell whether many stack pointer alterations are proper, so it uses a heuristic. If the stack pointer has been moved less than 512 kilobytes, the stack allocation is a controlled one and is allowed. If it has moved by more than 512K, it is assumed to be accidental, and the program is sent a SIGSEGV. This heuristic has an obvious flaw. To fix it, Berkeley made the limit not really 512K, but rather the `stacksize' resource limit for the process. This is set to 512K by init, and inherited by all children. It can be changed with the setrlimit() system call, or with the C shell's built-in `limit' command: limit stacksize 1m will raise it to one megabyte; unlimit stacksize will raise it to the kernel's configured maximum, probably 16M. Incidentally, on all machines with which I have worked, large arrays are more efficiently accessed when static than when on the stack. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu