bad-alloc

Bad alloc is thrown

与世无争的帅哥 提交于 2019-11-27 09:46:41
I am getting a 'bad_alloc while trying to work with boost managed shared memory. I've copied the boost example from their quick guide for the impatient and incorporated my own changes. MY code is below, I've commented out the example stuff and wrote my own below it. I've also put in some debugging and testing stuff. Does anyone have any ideas? Any help is greatly appreciated! -M #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/allocators/allocator.hpp> #include <boost/interprocess/containers/string.hpp>

How to deal with bad_alloc in C++?

浪子不回头ぞ 提交于 2019-11-27 06:29:40
There is a method called foo that sometimes returns the following error: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Abort Is there a way that I can use a try - catch block to stop this error from terminating my program (all I want to do is return -1 )? If so, what is the syntax for it? How else can I deal with bad_alloc in C++? You can catch it like any other exception: try { foo(); } catch (const std::bad_alloc&) { return -1; } Quite what you can usefully do from this point is up to you, but it's definitely feasible technically. In general you

Bad alloc is thrown

若如初见. 提交于 2019-11-26 14:51:23
问题 I am getting a 'bad_alloc while trying to work with boost managed shared memory. I've copied the boost example from their quick guide for the impatient and incorporated my own changes. MY code is below, I've commented out the example stuff and wrote my own below it. I've also put in some debugging and testing stuff. Does anyone have any ideas? Any help is greatly appreciated! -M #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/map.hpp> #include