www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/02/20:47:22

Date: Sun, 2 Feb 1997 20:35:36 -0500 (EST)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: Christian Bird <cbird AT byu DOT edu>
cc: djgpp AT delorie DOT com
Subject: Re: Dynamically allocated arrays
In-Reply-To: <32F51954.6B69@byu.edu>
Message-ID: <Pine.GSO.3.95.970202203012.20758A-100000@hops.cs.jhu.edu>
MIME-Version: 1.0

On Sun, 2 Feb 1997, Christian Bird wrote:

> Hello,
> 	Is there a limit to the size of an array that can be allocated?  Right
> now I'm writing a maze generation program and I input the size of it
> from the user and dynamically allocate the array I need.  Here is the
> code.
> 
> struct cell
> {
>         int left, up, right, down, used;
> };
> 
> cell ** maze;

I think you mean "cell **make_maze;" here

> int i;
> 
> make_maze = (cell **) malloc(max_width*sizeof(cell *));
> for (i = 0; i < max_width; i++) make_maze[i] = (cell *)   
> malloc(max_height*sizeof(cell));
> 
> The program compiles and runs fine, making mazes of arbitrary sizes, but
> when I hit a certain size, it dies on me.  I find that if max_width is
> 198, max_height can be around 80 but if it gets to near 100 the program
> dies.  I'm assuming that maybe the array has to be within a certain
> size?  I tried changing the int's in the cell struct to char's so they
> would be smaller, but the program still died at the same numbers.  If
> anyone knows why this is or how to avert it I would be very
> appreciative.  Thanks!
> 
> Christian Bird
> cbird AT byu DOT edu
> 

I assume you're using C++?  (In C, you have to explicity use "struct cell"
rather than just "cell" unless you've typedef'd it already.)  I have no
problem running your program fragment with width == 200 and height == 100.
Struct cell should require around 20 bytes, so 200 * 100 * 20 = 400K,
which is not much by DJGPP standards.  On my 16 MB machine even larger
matrices work fine.  Could you elaborate a little more on your problem,
because I don't think it's due to insufficient memory?



						---Michael Phelps
						   morphine AT cs DOT jhu DOT edu


                               CH3
                               |
                               N
                             / |
                     ______/   |
                    /      \   CH2
             _____/         \__|__      
           //     \\        /  |  \\     
         //        \\______/___CH2 \\  
          \        /       \       /
           \______/         \_____/
          / ------ \       /      \
        OH           \   /         OH
                       O
 
                   Morphine



- Raw text -


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