What is the limit of multidimensional vectors?

2

I'm running a test and it gives me an error when I try to create a vector [1000] [1000]. Are there limits for vectors?

The error code ( Application stops responding ) is as follows:

int main (){

    int DIM_X = 1000;
    int DIM_Y = 1000;

    int vectorMD[DIM_X][DIM_Y];
    int x,y;

    for(x=0;x<DIM_X;x++){
        for(y=0;y<DIM_Y;y++){
            vectorMD[x][y] = x;
        }
    }
}
    
asked by anonymous 12.02.2017 / 14:01

2 answers

0

Good,

After several tests, with different IDE / compilers and OS, I got the same error. After some research, I found an explanation that seemed valid and that after testing did not make a mistake. In summary, I was wanting to test performance in populating a 1000x10000 vector, in different ways but would define and initialize that vector within a function, so the scope is local and the stack has more restrictive boundaries. Defining the vector as a global variable no longer gives errors. And so, I think I've noticed the problem.

Cumps

    
20.02.2017 / 09:41
2

The limit is the amount of virtual memory available, which is usually much larger than the computer's RAM. That is, there is no limit.

In fact this code has no errors as can be seen below. I just gave it a bigger deal. I have not changed the size of the dimension variable, but usually if uses #define or const or enum . .

If you are in an IDE, especially a bad one, type Dev C ++, the problem is in the IDE.

#include <stdio.h>

int main () {
    int DIM_X = 1000;
    int DIM_Y = 1000;
    int vectorMD[DIM_X][DIM_Y];
    for (int x = 0; x < DIM_X; x++) {
        for (int y = 0; y < DIM_Y; y++) {
            vectorMD[x][y] = x;
        }
    }
}

See running on ideone . And at Coding Ground . Also put it on GitHub for future reference .

    
12.02.2017 / 14:45