c++ - error while declaring double array of size 150000? -
this question has answer here:
- segmentation fault on large array sizes 5 answers
i developing code in there need declaring array of double of size 150000 , when 1 array declared code running successfully.if declare 2 arrays while execution terminates throwing exception.
code : double a[150000]; double b[150000];
if declare executes perfectly.if declare both , b terminates. can suggest how resolve this?
the 2 arrays overflowing stack (assuming local variables). dynamically allocate memory arrays instead, using std::vector
manage memory you:
std::vector<double> a(150000); std::vector<double> b(150000);
even though std::vector
instances on stack, std::vector
dynamically allocates memory internally data on heap, avoiding stack overflow.