From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Help me understand memory limits!! Date: Wed, 01 Apr 1998 18:38:41 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 29 Message-ID: <3522D001.4E1@cs.com> References: <3520a3d4 DOT 0 AT news DOT pacificcoast DOT net> NNTP-Posting-Host: ppp217.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Aquinas wrote: > > So in a DPMI/Protected mode environment like DJGPP, why can't you have a > big-ass array like int x[1000000]? Is there a good explanation of this > somewhere? Any help would be much appreciated. Of course you can have an array that big (assuming you have at least 4 MB of physical+virtual memory available). The problem is that automatic arrays, such as the one in your code, are allocated on the stack, which is only 256K by default in DJGPP programs. Trying to grab more than this will cause your programs to behave very strangely, if not crash outright. There are three solutions. The first is to declare the array static instead of automatic; i.e., with the 'static' keyword or globally. The second is to dynamically allocate it, via malloc() and family. The third is to manually increase the size of the stack. This issue is discussed in detail in chapter 15.9 of the DJGPP Frequently Asked Questions list, which I suggest you read. hth -- --------------------------------------------------------------------- | John M. Aldrich | "Always listen to experts. They'll | | aka Fighteer I | tell you what can't be done, and why.| | mailto:fighteer AT cs DOT com | Then do it." | | http://www.cs.com/fighteer/| - Lazarus Long | ---------------------------------------------------------------------