Re: why boost:shared_ptr so slower?
Juha Nieminen wrote:
Sam wrote:
Casting from any superclass to a subclass incurs a penalty
To use C++ terminology: Casting from any base class to a derived class
incurs a penalty...
I don't think that's true. If the compiler can see both class
declarations and there is a simple inheritance relation between them
(with no virtual functions in the derived class), the pointer doesn't
have to be modified in any way and this decision can be done at compile
time. The cast will effectively not create any machine code whatsoever.
To use dynamic_cast to convert from a base type to a derived type, the
base type must have at least one virtual function. dynamic_cast has to
check whether the type of the object is, in fact, the derived type. If
not, it returns a null pointer or throws an exception, depending on
whether the dynamic_cast is targeting a pointer or a reference.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)