I am guessing that idata
is a local variable. The problem is that local variables are stored on the stack (technically "automatic storage"), and the stack is much smaller than the 6400 megabytes you're trying to allocate on it. Allocating that much storage on it causes a stack overflow.
Try
unsigned char** idata = new unsigned char*[DIM1];
for (int i = 0; i < DIM1; ++i)
idata[i] = new unsigned char[DIM2];
// or
unsigned char (*idata)[DIM2] = new char[DIM1][DIM2];
To allocate it in the free store and you shouldn't have a problem.
EDIT:
I just looked at the tags and didn't see you were only talking about C. If so, you can do the same thing but use malloc
instead of new
:
unsigned char** idata = malloc(sizeof(unsigned char*) * DIM1);
for (i = 0; i < DIM1; ++i)
idata[i] = malloc(DIM2);
// or
unsigned char (*idata)[DIM2] = malloc(DIM1 * DIM2);
And don't forget to free
(or delete[]
for C++) the memory you allocate to avoid memory leaks.