Xref: news2.mv.net comp.os.msdos.djgpp:6550 From: lehmann AT mathematik DOT th-darmstadt DOT de (Alexander Lehmann) Newsgroups: comp.os.msdos.djgpp Subject: Re: Flat Memory Questions Date: 29 Jul 1996 17:27:57 GMT Organization: Technische Hochschule Darmstadt Lines: 38 Message-ID: <4tisat$139h@rs18.hrz.th-darmstadt.de> References: NNTP-Posting-Host: fb0408.mathematik.th-darmstadt.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp David M Barrett wrote: : 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? Arrays defined inside of functions are usually not static, unless you add the keyword static to it. If you have an automatic array inside a function, the necessary memory will be allocated on the stack (well, allocated is not really right, the stack pointer is reduced appropriately), which means that you put a 1MB object on the stack. Since the default stack is usually 256 or 512k, you will overflow the stack. Either you can increase the stack size or you can use a dynamic malloc, but you have to remember to free that when you don't need it anymore (well, in main, you can just exit, but any other function). bye, Alexander -- Alexander Lehmann, | "On the Internet, alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows lehmann AT mathematik DOT th-darmstadt DOT de (plain) | you're a dog." !!CHANGED!!