Is there any limit on the size of a std::stack?
I am using a std::stack<std::pair<int,std::string>> as my stack, and when the number of entries exceeds roughly 1 million, I am getting a runtime error.
Is this due to a restriction on the size of std::stack?
std::stackis a container adapter. It is merely a front for some other container, that makes it look like a stack. Consider thatstd::vectorcan be treated like a stack if you replace the namepushwithpush_backand the namepopwithpop_back. Thus, any size limits or similar are going to be the result of the backing container, notstd::stack.The default backing container for
std::stackisstd::deque(N3376 23.6.5.2 [stack.defn]). The standard requires thatstd::dequeprovide amax_sizemember function (N3376 23.3.3.1 [deque.overview]/2), which tells you the maximum number of elements thatstd::dequecan hold according to implementation limits. This will typically be something likestd::numeric_limits<std::deque<t>::size_type>::max().However, it is more likely that you are either running into machine memory limits, or have some bug elsewhere in your application causing the runtime error.