When should std::nothrow be used?

后端 未结 9 1543
误落风尘
误落风尘 2020-12-30 20:27

What is the ideal usage of std::nothrow?

相关标签:
9条回答
  • 2020-12-30 21:28

    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!

    0 讨论(0)
  • 2020-12-30 21:30

    As I understand it, pretty much never and none.

    0 讨论(0)
  • 2020-12-30 21:32

    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.)

    0 讨论(0)
提交回复
热议问题