From: Sengan DOT Short AT durham DOT ac DOT uk Message-Id: <720.9607281807@ws-ai5.dur.ac.uk> Subject: Re: Flat Memory Questions To: dbarrett AT engin DOT umich DOT edu (David M Barrett) Date: Sun, 28 Jul 1996 19:07:40 +0100 (BST) Cc: djgpp AT delorie DOT com In-Reply-To: from "David M Barrett" at Jul 28, 96 10:58:27 am Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > > Wow, thanks a lot. I to malloc a meg and it worked just fine. But, when > I tried to defind a static array (ie- char Array[1024 * 1024]) I got a > wierd runtime error > > Exiting due to signal SIGSEGV > Stack fault at ... > eax=... > ebp=... > Call from traceback EIPs: > 0x000015b9 > > (the ...'s should be replaced with a ton of numbers and info). > > I tried to allocate the array on the first line of the main function. > The rest of the program is simply printf statements (except for a line > that sets one of the array values to 5, but it never gets that far). Is > there something wrong with allocating a buffer this way? void main (void) { char Array[1024*1024]; ...} Array is put on the stack. But there is only 256Kb on the stack, so the rest of your stack is all over your program. Anyway it is bad practice to use large amounts of stack. You should allocate it dynamically if you want big amounts of memory. char Array[1024*1024]; void main ( void ) { ... } Array is now static: ie a 1Mb array is made inside your executable, working but leading to a bloated >1Mb executable! Third choice: malloc: dynamic, no disadvantages. Sengan