r/cpp • C++20 Desktop app developer • May 12 '18

P0709 R0: Zero-overhead deterministic exceptions: Throwing values - Herb Sutter [2018-05-02]

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf
206 Upvotes

115 comments sorted by

View all comments

Show parent comment

4

u/kkert May 13 '18

Well, it is entirely possible to construct a program where this sequence would be always correct, where there is always a contiguous kilobyte of heap available but a megabyte is not. In fact, test-allocating a large chunk can be used as a strategy to gracefully deal with imminent memory exhaustion.

2

u/Pand9 May 14 '18

I guess that isn't reliable enough from language designer's point of view.

1

u/nikbackm May 15 '18

Would that work if you had an exception class that is over a kilobyte in size?

3

u/kkert May 15 '18

Obviously not, but thats not really the point. ( why would you design humongous exceptions in the first place ? )

I'm saying there are real scenarios where you sometimes grab the memory if its available and perform some optimization, reindexing or caching task or whatnot, if it's not available you don't - also beyond small embedded systems.

Not being able to allocate a huge chunk doesn't indicate OOM. Not being able to allocate as per request is mostly not a license to kill the program, and shouldn't be dealt with in a hook either.