Building a struct array with size [x>65535] throws 0xC00000FD error
, even if x is declared as int64_t
, but inconsistently. Will work fine in one line, not in the next.
int64_t length;
length = (pull from other code);
Foo foo[length];
//^ this works
Foo2 foo2[length];
//^ this one doesn't
Is this a problem with array construction? C++ max? Compiler/memory limit?
VLA (Variable Length Arrays) aren't in standard C++. This means the following is illegal (even if it works):
int length;
cin >> length;
int array[length];
What is 0xC00000FD
error code? It means stack overflow exception. That means you exceeded the stack limit set by your operating system. Since you are on windows, your stack limit by default is 1 MB.
Use the heap.
int* myArray = new int[length];
//or even better
std::vector<int> myArray;
myArray.reserve(length);
You will blow the stack, as you only have a small stack (I think the default is at around 1MB) and VLA arrays are allocated on the stack. (65535*sizeof(int)==~256kb) 256 kb is not the whole stack, but if you allocate another one, you are at 512kb. That's around the half of the stack. Add call frames and other locals and you will pass the size soon ==> Stackoverflow
User contributions licensed under CC BY-SA 3.0