Re: C++ exception implementation (tangent)
:I'd be interested in details there. My understanding is that setjmp
:saves processor registers in a jmpbuf, and that longjmp restores
:them. Neither sounds exactly high-overhead, certainly less than a
:chain of function returns.
:
:Greg
On a modern processor the branch predicition cache generally makes
procedure calls virtually free. Overheads can be as low as 0 ns and
are typically in the 0-10ns range. On the otherhand, saving and
restoring a register set involves very heavy interactions with the
memory subsystem. Writing out the register set will fill up the
write staging buffer and stall the cpu, reading in the register set will
saturate the memory units and stall the cpu, even if the data is
not going to be immediately used. A setjmp/longjmp combination costs
somewhere on the order of 200ns.
Procedure call and return is MUCH faster then register save and restore
these days.
Using setjmp/longjmp *just* to try to avoid popping a bunch of call
level is a bad idea. It makes the code confusing and difficult to
read and understand. setjmp/longjmp should only be used when there is
no other choice.
-Matt
Matthew Dillon
<dillon@backplane.com>
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):