News for hackers. Stuff that matters.
Re:I disagree with Linus Torvalds about C++ (2009) by amelius on Monday December 24, 2018 @07:48AM (#18751883)
Another potential problem is that "new" can throw an exception.
Re:I disagree with Linus Torvalds about C++ (2009) by monocasa on Monday December 24, 2018 @07:59AM (#18751924)
In practice they don't on a lot systems. Last time I checked glibc baked in Linux's overcommit by default nonsense, just throws up it's hands and says 'malloc never fails'.
Re:I disagree with Linus Torvalds about C++ (2009) by vbezhenar on Monday December 24, 2018 @08:42AM (#18752069)
That's not exactly correct. You can set ulimit and malloc will happily fail. And ulimit is pretty standard tool.
Re:I disagree with Linus Torvalds about C++ (2009) by monocasa on Monday December 24, 2018 @10:39AM (#18752584)
ulimit on the resident set size hasn't worked since the Linux 2.4 days
Re:I disagree with Linus Torvalds about C++ (2009) by gpderetta on Monday December 24, 2018 @09:08AM (#18752187)
There are 4 options: 1) allocation can't fail for whatever reason. So new won't ever throw.

2) allocation can fail but you do not care to handle it. Your application will abort on an exception which is the best scenario.

3) allocation can fail and you want to handle it non locally (for example in a constructor). Exceptions work well in this scenario.

4) allocation can fail and you want to handle it locally: new(nothrow) is your friend. Remember to check for '!= nullptr'.

Re:I disagree with Linus Torvalds about C++ (2009) by amelius on Monday December 24, 2018 @09:35AM (#18752289)
Exceptions require special stack-unwinding logic, which may not be adequate for a kernel (?)
Re:I disagree with Linus Torvalds about C++ (2009) by gpderetta on Monday December 24, 2018 @09:42AM (#18752313)
Sure (although there is work ongoing to fix that), but that's only relevant for point 3 and in that case 4 is an option.