[C++-sig] design question

Hans Meine hans_meine at gmx.net
Thu Feb 22 21:52:21 CET 2007


On Thursday 22 February 2007, Neal Becker wrote:
> I guess I was wondering if the use of boost::shared_ptr would add even more
> overhead to the virtual function calls, and if there was a more efficient
> (but still easy) approach.

AFAICS it is worth using a shared_ptr<> just for the sake of easy refcounting 
and memory handling.  If need calls to virtual functions at maximum speed, 
you could still store an /additional/ raw pointer.  That *may* be worth it 
depending on what you algorithms do (e.g. if both just do "return 0;" 
or "return 42;") - IIRC shared_ptr::operator-> contains an assert that the 
pointer is != NULL.  In case of -DNDEBUG I think it's "just" an additional 
indirection, which should be neglectable for most functions that contain 
non-trivial algorithms.

Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070222/d7d7f0de/attachment.pgp>


More information about the Cplusplus-sig mailing list