You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
General idea is to allow "nothrow" allocation of shared_ptr class of objects from smart_ptr library, however without need to go through expensive exception handling code, which can be ofter either disabled or it's usage available only in certain scopes (e.g. kernel mode code).
In such cases, developers may want to simply handle errors instead of crashing entire thread.
I have also added BOOST_SP_EMBEDDED ifdefs, which allow developer to disable any APIs which may throw. Currently it requires using sp_nothrow_tag to constructors. Plain functions get try prefix, such as try_make_unique or try_make_shared. If anything fails, they simply return empty smart pointer. Another method is reset, which now becomes try_reset - instead of leaving object in "partial" state, it doesn't modify the object if memory allocated would fail.
Are there any plans to introduce such feature in the library ?
The text was updated successfully, but these errors were encountered:
It "works" if you expect program to crash on OOM (not good idea in e.g. kernel mode), however the idea is to recover the program in exception-less environment or when exceptions are completely unnecessary.
Shared_count will crash on OOM because it can recover only through throw. Make_shared and friends depend on shared_count and they're going to have the same issue. For make_unique workaround is just to initialize unique_ptr(new(std::nothrow) Foo)
Right. So the suggestion is, for every function or constructor that allocates, introduce a non-throwing overload that returns an empty pointer instead?
Can you summarize these new additions (as in, list their declarations here) so that I don't have to infer them from the diff?
I have created Proof of Concept inside https://github.com/jplcz/smart_ptr/pull/1/files
General idea is to allow "nothrow" allocation of shared_ptr class of objects from smart_ptr library, however without need to go through expensive exception handling code, which can be ofter either disabled or it's usage available only in certain scopes (e.g. kernel mode code).
In such cases, developers may want to simply handle errors instead of crashing entire thread.
I have also added
BOOST_SP_EMBEDDED
ifdefs, which allow developer to disable any APIs which may throw. Currently it requires usingsp_nothrow_tag
to constructors. Plain functions gettry
prefix, such astry_make_unique
ortry_make_shared
. If anything fails, they simply return empty smart pointer. Another method isreset
, which now becomestry_reset
- instead of leaving object in "partial" state, it doesn't modify the object if memory allocated would fail.Are there any plans to introduce such feature in the library ?
The text was updated successfully, but these errors were encountered: