<p>I have a (potentially dumb) question about the C++ STL.  When I make a container (vector, set, map, etc), is it allocated on the stack or on the heap?  If I make a set and put 5 million strings, will I have to worry about a stack overflow?</p>

[{'answer_id': 33313, 'author': 'Brian Stewart', 'author_id': 3114, 'author_profile': 'https://Stackoverflow.com/users/3114', 'pm_score': 4, 'selected': True, 'text': '<p>STL classes by default allocate their internal buffers from the heap, although these classes also allow custom allocators that allow a user to specify an alternate location to allocate from - e.g. a shared memory pool.</p>\n'}, {'answer_id': 33466, 'author': 'Mat Noguchi', 'author_id': 1799, 'author_profile': 'https://Stackoverflow.com/users/1799', 'pm_score': 2, 'selected': False, 'text': "<p>The default allocator for STL containers uses operator new and delete, so it's whatever those route to for the type being contained. (In general, it comes from the heap unless you do something to override that.)</p>\n\n<p>You will not get a stack overflow from allocating 5 million strings. Even if you made a stack based allocator, it would probably overflow before you even inserted one string.</p>\n"}, {'answer_id': 39267, 'author': 'Xavier Nodet', 'author_id': 4177, 'author_profile': 'https://Stackoverflow.com/users/4177', 'pm_score': 0, 'selected': False, 'text': '<p>The container itself is allocated where you decide (it can be the stack, the heap, an object\'s member, etc) but the memory it uses is, by default, as others described, taken on the Free Store (managed through new and delete) which is not the same as the heap (managed through malloc/free).</p>\n\n<p><a href="http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.3" rel="nofollow noreferrer">Don\'t mix the two!</a></p>\n'}]
['https://Stackoverflow.com/questions/33306', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2147/']