Re: Exceeding memory while using STL containers
Kai-Uwe Bux wrote:
blwy10 wrote:
What happens when in the process of using STL containers, we insert
so many elements that our computer runs out of memory to store them.
What happens then? I assume that this behaviour is
implementation-defined and dependent on what STL am I using and what
OS I am running but I'm just curious to know what would/should
typically happen.
No. The standard containers do all allocations through std::allocator
unless you specify an allocator of your own. When std::allocator
cannot do an allocation, it will throw std::bad_alloc.
Maybe. It depends on the program (e.g. if you've not replaced
the new handler, or the global operator new), and a lot of other
things -- all std::allocator is required to do is use ::operator
new. The default version of the global operator new will throw
std::bad_alloc if 1) it is able to determine that the request
will fail, and 2) you haven't replaced the new handler.
One thing is certain: you cannot count on recovering from an out
of memory situation on most platforms.
--
James Kanze kanze.james@neuf.fr
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]