m***@gmail.com
2018-10-17 19:16:02 UTC
In P0709, Herb Sutter proposes a zero-overhead deterministic variation of
the exception mechanism by throwing a value of a size equivalent to two
pointers.
I generally like the proposal a lot. I am doing HPC programming and
micro-controller programming and do see a lot of benefit in squelching
objections to the use of exceptions.
However, when it comes to the treatment of heap exhaustion and, more
importantly, the impact of it on the standard library, I am finding the
proposal to be disturbing.
Also because it goes against the ideas of writing a single generic routine
for an algorithm because it seems to imply that every time I want to write
an algorithm that involves a standard library function that does a memory
allocation, I should write both a regular version and a try_*** version.
So Herb wants that the vector<T> push_back should be noexcept while the
try_push_back can throw.
Though, I can see the use for having a try_*** in places, I wonder why he
does not suggest to let the allocator used make the decision? Something
that my code can use. If I run out of memory, it is out of the question
that the code would crash. Instead it should be reported to the user that
she needs to provide a bigger buffer. I can do that by using an allocator
that throws an exception. Using a solution like I suggest above would allow
to still have noexcept if the user is fine with terminate being called and
still allow to handle cases like mine gracefully in a way that I can report
to the caller as they are expecting. If the standard library always calls
terminate on failure of allocation, then I'll have to resort to not using
the standard library, but using a modified clone of it. This would be
ironic, as one of the motivations of his proposal in the first place is
that people are not using the standard library.
the exception mechanism by throwing a value of a size equivalent to two
pointers.
I generally like the proposal a lot. I am doing HPC programming and
micro-controller programming and do see a lot of benefit in squelching
objections to the use of exceptions.
However, when it comes to the treatment of heap exhaustion and, more
importantly, the impact of it on the standard library, I am finding the
proposal to be disturbing.
- For each standard function for which allocation is the only
reportable error, make the function noexcept. (We expect this to result in
making a large majority of functions in the standard library noexcept,
including default and user-replaced ::operator new.)
- For code that wants to handle heap allocation failures, provide
explicit âtry to allocateâ functions including the existing new(nothrow)
However this approach is disturbing. It is essentially saying to go back
to an equivalent of testing an error code on return of every single call.reportable error, make the function noexcept. (We expect this to result in
making a large majority of functions in the standard library noexcept,
including default and user-replaced ::operator new.)
- For code that wants to handle heap allocation failures, provide
explicit âtry to allocateâ functions including the existing new(nothrow)
However this approach is disturbing. It is essentially saying to go back
Also because it goes against the ideas of writing a single generic routine
for an algorithm because it seems to imply that every time I want to write
an algorithm that involves a standard library function that does a memory
allocation, I should write both a regular version and a try_*** version.
So Herb wants that the vector<T> push_back should be noexcept while the
try_push_back can throw.
Though, I can see the use for having a try_*** in places, I wonder why he
does not suggest to let the allocator used make the decision? Something
void push_back (const value_type& val) throws( can_throw_v<Alloc> ) ;
In my HPC work, I write library in which users can supply a memory bufferthat my code can use. If I run out of memory, it is out of the question
that the code would crash. Instead it should be reported to the user that
she needs to provide a bigger buffer. I can do that by using an allocator
that throws an exception. Using a solution like I suggest above would allow
to still have noexcept if the user is fine with terminate being called and
still allow to handle cases like mine gracefully in a way that I can report
to the caller as they are expecting. If the standard library always calls
terminate on failure of allocation, then I'll have to resort to not using
the standard library, but using a modified clone of it. This would be
ironic, as one of the motivations of his proposal in the first place is
that people are not using the standard library.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cc411e93-53a3-4b24-8e02-68fda610c15e%40isocpp.org.
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cc411e93-53a3-4b24-8e02-68fda610c15e%40isocpp.org.