I have approx. 2 GB of free DRAM on my computer. Compiling either a std::array or the standard array:
#include <iostream>
#include <array>
int main(int argc, char *argv[]){
// int* a = new int[500000000];
std::array<int, 2000000> a;
}
with:
$ g++ -std=c++11 main.cpp -o main
./main
works for both arrays. Changing the size of the std::array to:
// ceteris paribus
std::array<int, 2095300> a;
leads to:
$ ./main
Segmentation fault (core dumped)
honestly, I am not sure whether or not this issue has already been addressed somewhere.
From my understanding, the std::array is created on the stack, and the int * ... array on the heap. Now my guess was that maybe my stack is simply not larger then the ~8mb, which compared to the 2 GB heap sounded disproportionate. Thus I also tried out:
//int a[2096000];
which also causes a segmentation fault. So my question is, what causes the Segmentation fault?
Thank you in advance.