Toward a better list iterator for the kernel
Toward a better list iterator for the kernel
Posted Mar 13, 2022 15:43 UTC (Sun) by ianmcc (guest, #88379)In reply to: Toward a better list iterator for the kernel by PengZheng
Parent article: Toward a better list iterator for the kernel
It depends on how exceptions are implemented by the compiler. Exceptions require RTTI, because you need to be able to match the type of the thrown object with a corresponding catch (...) clause. When you have a try {...} block, the compiler needs to know how to unwind the stack. Most modern compilers use a 'zero overhead' model, meaning that the runtime cost (in CPU time) is basically zero for the no-exception case. ie, there is no penalty for having a try {...} block if no exception is actually thrown. The way they do this is with a lookup table from the instruction pointer to the exception handler for the current stack frame. This basically doubles the code size. Also the cost of throwing an exception is quite high, so you normally only want to do it for really exceptional events, not as an alternative to a return statement. But in some cases exceptions can be faster than return codes, i.e. since you need to check the return code every time, in a tight loop using exceptions might be faster.
More info: https://wg21.link/p1947
