3 ms·
> It just comes for free To be fair, specifically the price is a hidden context passed to every function. Hiding it means the programmer needn't expend effort
by tialaramex 4y ago
> It just comes for free
To be fair, specifically the price is a hidden context passed to every function. Hiding it means the programmer needn't expend effort thinking about it as they would if you did this by hand, but in performance terms this isn't really free.
- astrange 4y agoThis can be implemented many different ways without losing a register (/ other parameter storage). It’s called dynamic scoping or thread local variables.
- _0w8t 4y agoThread-local variables are implemented using a reserved register. Essentially thread-locals in C++ are the hidden context.
- astrange 4y agoThat doesn't "lose" a register because the program already wasn't using it.
- LegionMammal978 4y agoTo be fair, they're implemented with one of the segment registers, at least on x86-64. So there isn't much else that programs could have used it for, since it takes a syscall just to set the value.