• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

How can you tell when a multimap insertion fails due to Out Of Memory

Quite simply, how can you tell when a multimap insertion fails due to running out of memory?  I expected that this would be easily found on Google but have had no luck.  My two guesses would be that it would return end() or that it would throw an exception but I haven't managed to find anything definitive.
0
iyac
Asked:
iyac
1 Solution
 
ambienceCommented:
Nope it will definitely not return end() because of an out of memory condition. I'm saying this because thats not a general design strategy in STL. The world is divided wrt whether new operator would throw std::bad_alloc when it fails to allocate memory or not. STL variant that favor exceptions - possibly this behavior is configurable - you can expect a std::bad_alloc exception. For others, I'm not sure - but i think it will just crash.

For example, VisualStudio has the define

#define _HAS_EXCEPTIONS 1

If you set this to 0 it will not throw std::bad_alloc.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now