1

Possible Duplicate:
How can I allocate a 2D array using double pointers?

I used VB 2012 Express to make a maze program.

It works really well even when I set ROW*COLUMN to 499*499, (the maze is an array: unsigned char maze[ROW][COLUMN]).

But one time I tried to make a super-giant maze of999*999, and the compiler gave me a "stack overflow" error.

I do know what it means, but is there any way to assign extra memory or even use some disk space to run my program?

Community
  • 1
  • 1

2 Answers2

2

You are allocating maze on the stack, and stack size is typically limited to between 1 and 8 megabytes. To overcome this limitation, allocate maze on the heap.

For suggestions on how to do this, see How can I allocate a 2D array using double pointers? and Heap allocate a 2D array (not array of pointers)

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012
2

You can either dynamically allocate your array (e.g maze = new char[ROW*COLUMN]) or allocate it globally (outside function scope), like

#define ROW 999
#define COLUMN 999

unsigned char maze[ROW][COLUMN];

int main(void)
{

}
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
arash kordi
  • 2,470
  • 1
  • 22
  • 24