delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/30/02:01:24

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: <Pine DOT SOL DOT 3 DOT 91 DOT 960728105107 DOT 6455B-100000 AT blazers DOT engin DOT umich DOT edu>
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 <dbarrett AT engin DOT umich DOT edu> 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!! <URL:http://www.mathematik.th-darmstadt.de/~lehmann/>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019