Mail Archives: djgpp/1997/02/04/13:12:09
In article <32F51954 DOT 6B69 AT byu DOT edu>, Christian Bird <cbird AT byu DOT edu> writes:
|>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;
|>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));
|>
|
[Christian then says that he has problems when max_width=198 and max_height
approaches 100]
You can have arrays far bigger than this with djgpp. The structure
you are talking about would only need 400K with the values you describe.
The problem may be to do with CWSDPMI and the maximum number of fragments
it can keep track of when required to move the program break boundary
(which internally is what malloc needs to do when it needs more heap.)
If this is the case, it would be resolved by calling malloc() fewer times
but asking for more each time. In your case, you can malloc() the whole
thing at once, and if you still want maze to be an array of pointers
to arrays of cells, you have:
cell *celltemp;
make_maze = (cell **) malloc(max_width*sizeof(cell *));
celltemp = (cell *) malloc(max_height*max_width*sizeof(struct cell));
for (i = 0; i < max_width; i++) {
make_maze[i] = celltemp;
celltemp += max_height;
}
That is assuming, of course, that your program dies on the malloc() call.
You didn't actually say where the program died, and with what message.
Since you aren't error trapping the malloc, it may be that your problem
is elsewhere entirely. If malloc can't get memory, it just returns NULL.
If you dereference that later, you have problems.
------------------------------------------------------------------------------
Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk
Systems Development Group Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley
University of London Computer Centre. ...ukc!ncdlab!K.Ashley
This is not a signature
- Raw text -