What does nothrow buy me?

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Nov 8 23:53:50 UTC 2020


On Sun, Nov 08, 2020 at 10:00:28PM +0000, random via Digitalmars-d wrote:
> On Monday, 26 October 2020 at 18:47:41 UTC, Q. Schroll wrote:
[...]
> > At first glance, one could assume a nothrow function can save the
> > compiler from the need to generate exception handling stuff for a
> > function. But since nothrow doesn't mean the function won't throw,
> > but merely that it won't throw an Exception, what optimizations does
> > nothrow enable?

The reason it's a bad idea to catch Throwable is because the compiler is
*not* obligated to generate exception handling stuff in nothrow
functions, even if a Throwable ends up going through that function..


[...]
> When you call functions which potentially throw, the compiler has to
> generate landing pads to handle exceptions if:
> 
> 1. You have a catch block.
> 2. You have to call destructors.
> 
> This does not directly impact runtime performance but it bloats the
> executable code (and it will probably impact runtime performance
> because of caching).
[...]

Nothrow functions can have exception handling code elided. So in that
case it will not incur the runtime cost.


T

-- 
Computers aren't intelligent; they only think they are.


More information about the Digitalmars-d mailing list