What is the ideal usage of std::nothrow
?
Only very few programs should ever allocate more than 1 GiB of memory, and since modern systems overcommit memory, new
will never return null or throw on these systems. Therefore, there is absolutely no point in checking the return value of new/malloc at all. Just keep your memory footprint down and let the out-of-memory-killer shoot down other processes!
As I understand it, pretty much never and none.
Perhaps if your application required nano-optimization and could not allow the overhead of exception handling, then maybe nothrow
would be needed.
Bear in mind that Stroustrup is pretty adamant that the programmer can turn off overhead in C++. (As a caveat though, just because you have the choice doesn't mean you should.)