|
Boost Users : |
From: Paul Johnson (gt54-boost_at_[hidden])
Date: 2005-06-24 03:04:45
Tan Kwee Heong wrote:
> Hi,
>
> I wish to reconcile the information provided from Scott Meyer's More
> Effective C++ Item 15, with that
> of Peter Dimov. Could someone post some URLs/referencess of Peter's
> comments, for
> my benefit?
>
> Thanks,
>
> "Vladimir Prus" <ghost_at_[hidden]> wrote in message
> news:d9dopb$3tg$1_at_sea.gmane.org...
>
>>Thomas Costa wrote:
>>
>>1. As Peter Dimov said (IIRC), exceptions are just non-local goto. In this
>>case, non-local goto is fine.
<disclaimer>
I didn't see Peter's comments.
</disclaimer>
When you execute a goto, you still have to unwind any enclosing blocks
in your function. If you jump out of a (nested) block, the compiler
destructs any objects which are local to those blocks. In this sense,
gotos and exceptions are similar.
Scott Meyer estimates that returning from a function via an exception
could be ~1000x slower than a normal return. However, exiting a block
via a goto is probably only marginally slower than a normal exit, since
the block still has to be unwound anyway (clean up stack/call
destructors) even in a normal exit.
PJ
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net