What is the limit of multidimensional vectors?

Asked

Viewed 131 times

2

I’m doing a test and it gives me an error when I try to create a vector[1000][1000]. There are limits to vectors?

The error code (application ceases to respond) is the following:

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;
        }
    }
}
  • 2

    What mistake do you get?

  • The error would be the application no longer responding?

  • Good, Answering questions that put me above: 1. The Error is not compilation, it is in execution. 2. The error you give is when executed: a windows message appears "The application stopped responding". I had no idea there were limits but as I’m going over a bit of C but on a Windows machine, I was confused. Yes, I’m using Devc+++ but I also tested it in Code:Blocks. I also compiled and ran it on a Powershell console. All failed. Something I’m missing. Cumps

  • How much memory you have in the machine, and what else is lurking in it?

  • Good, 8GB and was running nothing else.

  • @pintasart Have any of the answers solved your question? Do you think you can accept one of them? See the [tour] how to do this, if you haven’t already done so. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

Show 1 more comment

2 answers

2

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

Actually this code has no errors as can be seen below. I just gave a larger organized in it. I didn’t change the size variable of the dimension, but usually if uses #define or const or enum.

If you are in an IDE, mostly a bad one, like 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;
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • The fact of the return of the function main was int but without explicitly returning a value does not interfere?

  • @Andersoncarloswoss does not.

  • 1

    @Andersoncarloswoss The compiler can give you a Warning on this, but Warning is not a compilation error.

  • @jsbueno the occupied memory will be 4MB.

  • ih...large scale error ... Hahahaha... I think I need to sleep more.

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 gave no error. In short, I was wanting to test the performance of filling a 1000x10000 vector in different ways but defining and initializing that vector within a function, so the scope is local and the stack has more restrictive limits. Defining the vector as a global variable no longer gives errors. And so, I think I have understood the problem.

Cumps

Browser other questions tagged

You are not signed in. Login or sign up in order to post.