[Interprocess] shared_ptr in a non-throwing mode

Hi Ion (and everyone else),
I'm a newbye and I have only one simple question:
how can I construct a shared_ptr in a non-throwing mode?
This example throw if there is enough space for MyType but isn't
enough for my_shared_ptr:
typedef managed_shared_ptr

El 06/04/2011 13:19, Pietro Versari escribió:
Hi Ion (and everyone else),
I'm a newbye and I have only one simple question: how can I construct a shared_ptr in a non-throwing mode?
This example throw if there is enough space for MyType but isn't enough for my_shared_ptr:
typedef managed_shared_ptr
::type my_shared_ptr; my_shared_ptr sh_ptr = make_managed_shared_ptr( segment.construct<MyType>("object to share", std::nothrow)(), segment);
Then it's a bug ;-) Boost version please? Best, Ion

2011/4/6 Ion Gaztañaga
El 06/04/2011 13:19, Pietro Versari escribió:
Hi Ion (and everyone else),
I'm a newbye and I have only one simple question: how can I construct a shared_ptr in a non-throwing mode?
This example throw if there is enough space for MyType but isn't enough for my_shared_ptr:
typedef managed_shared_ptr
::type my_shared_ptr; my_shared_ptr sh_ptr = make_managed_shared_ptr( segment.construct<MyType>("object to share", std::nothrow)(), segment); Then it's a bug ;-) Boost version please?
1.45.0, 1.46.0, 1.46.1 (gcc 4.4.3 and icc 12.0.2; OS: Ubuntu 10.04).
But I have one question: these pieces of code are equivalent?
typedef managed_shared_ptr

El 06/04/2011 13:19, Pietro Versari escribió:
Hi Ion (and everyone else),
I'm a newbye and I have only one simple question: how can I construct a shared_ptr in a non-throwing mode?
This example throw if there is enough space for MyType but isn't enough for my_shared_ptr:
typedef managed_shared_ptr
::type my_shared_ptr; my_shared_ptr sh_ptr = make_managed_shared_ptr( segment.construct<MyType>("object to share", std::nothrow)(), segment);
Reviewing again the code, it is not a bug. make_managed_shared_ptr creates a shared ptr from the object but it must allocate new memory for the reference count. So it can throw. What is missing is a new make_managed_shared_ptr() that also is nothrow. I will add it for Boost 1.47: my_shared_ptr sh_ptr = make_managed_shared_ptr ( segment.construct<MyType>("object to share", std::nothrow)() , segment , std::nothrow); Best, Ion
participants (2)
-
Ion Gaztañaga
-
Pietro Versari