I'm doing a college assignment with C++. I mostly have been instructed in C, so I'm putting in some effort to practice more "idiomatic" C++.
In C, I had no issues working with a large dynamically allocated array:
int* board = (int*) malloc(2048 * 2048 * sizeof(int));
In C++, as I understood, malloc shouldn't be used, nor new and delete, and instead RAII is king. Instead of worrying about allocation and freeing of memory myself, I should prefer to use the STL.
However, this code does not run (but does compile):
std::array<int, 2048 * 2048> board;
With Valgrind, I noticed that the amount of memory attempted to be allocated on the stack (around 8.4 million ints) goes way beyond what the OS is willing to do.
What would be the C++ way to work with large arrays?