Thủy Lực Trần Thủy Lực Trần - 2 months ago 19
C++ Question

C++ local container

In C++ when I use array with determined size like:

int a[10000];
in a function as a local variable, the allowed size is smaller than if I declare it as global variable.

I know this is due to the stack size of function.

But what about containers like vector, list, queue, stack, priority_queue, map, etc. ? Are they limited when being local variables like
int a[10000]
?

Answer

std::array has the same space constraints as C-style arrays do. All other standard containers allocate their memory dynamically, and are thus not limited by stack size.