Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-09-11 08:36:15


It seems to me that this went unnoticed because it was in a sub-thread,
so I'd like to give it another push with its own thread now :)

Ed Brey wrote (abbridged):

<quote>

For instance, when I examine the optimized code generated by VC 7.1 from
the technique used by shared_ptr et al, I find code that does a run-time
fetch of the "unspecified" member address from a non-immediate variable.
  Another way to put it is that for shared_ptr, these two fragments
generate different code:

if (ptr.get()) ...
if (ptr) ... // Less efficient.

</quote>

This inefficiency is caused by shared_ptr's current safe-bool-idiom. A
solution is the use of the safe-bool-idiom I first showed here:
http://lists.boost.org/MailArchives/boost/msg38164.php and that found
it's way into the operators library, see the CVS version and have a look
at bool_testable.

This new idiom should be as safe as the current one, but it uses a real
operator bool() for bool conversion, so no overhead can slip in. To be
fair, it also has one drawback: The error message a user receives when
converting a shared_ptr to int, float, ... is not as nice as today.

As I think that efficiency is more important than a nice error message,
I'd like to propose changing shared_ptr's code appropriately to avoid
the overhead imposed by the current safe-bool-idiom. Comments?

Regards, Daniel

-- 
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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