Mail Archives: djgpp/1997/05/03/22:30:52
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 <stdio.h> // 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
- Raw text -