Boost logo

Boost :

Subject: Re: [boost] [inspect] exceptions (FW: [Boost-users] no exceptions)
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-03-28 06:58:05


Brian Wood wrote:
> Robert Kawulak:
> > You can eliminate the try/catch from the code. For example,
> instead of:
> >
> > try {
> > // do sth dangerous using cmpRead
> > } catch(...) {
> > cmpRead = 0;
> > throw;
> > }
> >
> > write:
> >
> > auto tmp = cmpRead;
> > cmpRead = 0;
> > // do sth dangerous using tmp
> > cmpRead = tmp;
>
>
> Thanks for that. I tried it. The implementation is available
> here -- http://webEbenezer.net/misc/rcb.hh . It's one line shorter
> than the version with the try/catch, but it adds 3 minor statements
> to the non-error path. On Fedora 14 with g++ 4.5.1 one of my
> executables increased in size by over 500 bytes when using
> the version without a try/catch. On Windows 7 with MSVC++ 10
> there wasn't any size difference in the executable. I find the
> try/catch version easier to understand though.

The size growth seems odd on the face of it, given that the variant code is pretty trivial (saving and restoring an int32_t). Have you looked into the assembly to find the difference? I can't imagine how an exception handler plus rethrow would take 500 bytes less than the alternative code (three unconditional writes of 32 bits each!). (Well, I guess one possibility could be that the extra 32b value (tmp) alters register usage and so leads to more instructions to shuffle things to and from main memory.)

Does the size growth buy performance?

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk