What does nothrow buy me?
random
frederick.mueller at existiert.net
Sun Nov 8 22:00:28 UTC 2020
On Monday, 26 October 2020 at 18:47:41 UTC, Q. Schroll wrote:
> Obviously, nothrow documents the behavior of a function and is
> checked when the code is available to the compiler.
>
> 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?
This is a bit old but anyway.
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).
I'm not a compiler expert, so take this with a grain of salt.
I found this very helpful to understand how exceptions work:
https://monoinfinito.wordpress.com/2013/04/23/c-exceptions-under-the-hood-14-multiple-landing-pads-the-teachings-of-the-guru/
I linked article 14 with landing pads but you should probably
start at the beginning ;)
More information about the Digitalmars-d
mailing list