Home > Mobile >  Cannot produce any output on increasing size of arr of vectors
Cannot produce any output on increasing size of arr of vectors

Time:01-21

I m using minGW compiler along with VScode on windows 10

Problem I m facing is provided below :

here I can see output while using an arr of vectors of size 1500

Hello World
Execution works

enter image description here

.

.

.

But on declaring an arr of vectors of large size I cannot receive any output in terminal enter image description here

How will I be able o work with an arr of vectors of size 150000 or more ?

CodePudding user response:

You blew up the stack. Every std::vector object occupies 24 bytes on the stack (in GCC's implementation). Now 150000 * 24 = 3.6 MB which may easily cause a problem for you.

Instead, try this (one of the easiest ways):

std::vector< std::vector<int> > v( 150'000 );

or maybe this:

std::vector< std::vector<int> > v( 150'000, std::vector<int>( 1000 ) );

The above statement will create a vector that owns 150000 other vectors each of which has 1000 elements initialized to 0.

  •  Tags:  
  • Related