I did a small amount of research on the allocation of std::array
and std::vector
My current (simplistic) understanding is:
std::vector
is an object that holds a pointer to its array/collection/buffer of values
std::array
is an object that holds its array/collection/buffer
A very incorrect but effective demonstration of this is
printf("%llu\n", sizeof(*new std::vector<uint64_t>(10)));
printf("%llu\n", sizeof(*new std::array<uint64_t, 10>));
24 (consisting of vector things)
80 (consisting of uint64_t[10])
Defining a variable defines it on the stack
Defining an std::array
defines/allocates it's array/collection/buffer on the stack - so why doesn't std::array<uint64_t, 1000000000000000> array
(1 PB) cause a stack overflow?
Why doesn't defining an object that exceeds the stack size on the stack not cause a segfault?