I have an array problem that i want to overcome, if i change the value of const int \"are\" to 2048 the program runs fine but at 8192 or even at 4096 ( just 130,000 elements
What everyone else said: you're trying to allocate a lot of stuff on the stack. A lot.
Instead, dynamically-allocate the memory buffer... by using a standard container for memory management:
std::vector<unsigned char> cmain(are);
You don't have to put the arrays on the stack in main(), you can just as well allocate them statically before entering the function. That will put them in an area that is not limited by the default stack size.
unsigned char cmain[are];
int array_inst[64]={0};
DataStructure_trus va;
DataStructure_init in;
int main() {
ftrus(cmain,array_inst,va);
finit(va,in);
cin.get();
}
Allocate the array dynamically, since there are often limits on how much data you can have on the stack (which is where automatic local variables typically end up):
unsigned char* cmain = new unsigned char[are];
You can start with allocating DataStructure_*
not in the stack. For instance by prepending the static
keyword.
static DataStructure_trus va;
static DataStructure_init in;
You are putting the data structure on the stack in main
, and it is pretty huge. You can either increase the stack size (depends on your system), or allocate the structure on the heap with new
or malloc
.