Re: Exceeding memory while using STL containers
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. To be more precise, I am using
Windows XP SP 2 and VC Toolkit 2003, including its STL
implementation. The container specifically is std::set.
Strictly speaking, it's undefined behavior. You've exhausted
the resource limits of your process. However, the standard does
provide an officially sanctionned means for the library to
handle this: raise an std::bad_alloc exception. In practice, on
systems which support detecting a failed allocation, when using
the default allocator, and you haven't replaced the new_handler,
you will usually get this. Not all systems support detection of
a failed allocation, however: I've had problems with this in the
past on AIX, Linux and Windows NT. (I know that AIX has since
fixed the problem, and that there are ways to configure Linux to
avoid it.) And of course, depending exactly on what you are
doing when you run out of memory, you may end up crashing
anyway.
--
James Kanze GABI Software
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! ]