Mail Archives: djgpp/1998/01/22/23:30:27
From: | "John M. Aldrich" <fighteer AT cs DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: use memory more than 1MB
|
Date: | Thu, 22 Jan 1998 23:18:14 -0500
|
Organization: | Two pounds of chaos and a pinch of salt.
|
Lines: | 37
|
Message-ID: | <34C81A06.18AF@cs.com>
|
References: | <01bd26e6$b95daea0$0100007f AT localhost>
|
NNTP-Posting-Host: | ppp244.cs.com
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
VAMPYR wrote:
>
> How to make DJGPP use memory more than 1MB(or more)?
It does so automatically; you need to do nothing special. However, you
must still obey the rules for creating valid C code (see below).
> This is my test file:
> ===========================
> void main()
> {
> char array[1024000];
> }
> ===========================
> I compiled with "gcc test.c -o test.exe" , but it appears error!
> How should I do?
You are declaring the array as an automatic variable, which means that
it goes on the stack. Since the default DJGPP stack is only 256k, the
array declaration completely blows the stack apart and begins writing
into invalid memory addresses, resulting in a crash.
You should NEVER put large objects on the stack, particularly not the
way you do it here. Either declare them statically (i.e., global or
with the 'static' classifier), or dynamically (i.e., with malloc()).
You can also increase the default stack size, but that is a really
horrid way to get the above code to work. More info on the stack can be
found in the DJGPP Frequently Asked Questions list, chapter 15.9.
P.S.: main() must always return an integer. This is a rule of ANSI C.
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| Plan: To find ANYONE willing to | http://www.cs.com/fighteer |
| play Descent 2 on DWANGO! | Tagline: <this space for rent> |
---------------------------------------------------------------------
- Raw text -