Re: C++ exception implementation (tangent)

看板DFBSD_kernel作者時間21年前 (2005/02/18 21:33), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/4 (看更多)
: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>
文章代碼(AID): #125Uwo00 (DFBSD_kernel)
文章代碼(AID): #125Uwo00 (DFBSD_kernel)