Date: Sat, 3 May 1997 22:08:46 -0400 (EDT) From: Michael Phelps To: Matthew Bennett cc: djgpp AT delorie DOT com Subject: Re: Simple newbie problem - arrays In-Reply-To: <01bc57a9$47894800$0b3e63c3@8652hvt73761> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On 3 May 1997, Matthew Bennett wrote: > Hi, > > I'm new to djgpp, and even C/C++. I'm not however new to programming ;) > Anyway, one of the cool things about djgpp is it's protected mode stuff, > allowing you to easily use extended memory. > I decided to try this out with a simple array. Here's my program: > > #include // I know I don't need this, but hey... > > int main(void) > { > int q[100][100][100]; > q[80][80][80] = 44; > printf("%d", q[80][80][80]); > return 0; > } > > This array should only use about a meg, and so it should have plenty of > space with extended mem etc. > However, when I run it the program quits with an error - presumably because > it ran out of memory. It works fine for small arrays though. > > How can I use large arrays like this - there must be a way in djgpp to > store them using extended memory. Yes, there is. You're allocating a huge automatic array, and you're asking for 100 * 100 * 100 * sizeof(int) = 4MB. This is all placed on the _stack_. Consequently, you need to use the stubedit program to change the stack size of the executable to be something greater than 4 megabytes (the default is 512K). Better solution: use malloc() or calloc(). > > Any suggestions? > > Thanks, > Matthew > ---Michael Phelps morphine AT cs DOT jhu DOT edu CH3 | N / | ______/ | / \ CH2 _____/ \__|__ // \\ / | \\ // \\______/___CH2 \\ \ / \ / \______/ \_____/ / ------ \ / \ OH \ / OH O Morphine