|
From: Matt B. <ma...@be...> - 2004-07-06 16:23:19
|
Guys, A couple of issues regarding smart pointers... Firstly I have been considering ways to reduce the overhead when using smart pointers and it seems that a lot of cycles can be saved by using references to pointers in function calls. This will save incrementing and decrementing the count with each call - there is no risk of the object needing to be deleted as the calling function will always hold a pointer to it. This should be especially useful for in-lines as they will optimize out nicely. The only things that are not safe (as far as I can tell) are storing references to smart pointers and passing references between threads - so don't do either. I will gradually move functions to use references to pointers rather than pointers - this will not affect any calling code. Secondly I have established how to safely use "polymorphic" smart pointers. This can be done providing the base class derives from RefCount<> and none of the derived classes do. Then a smart pointer to a base class can safely point to a derived class and the correct virtual functions will be called as expected. However... if you do this please remember to include a virtual destructor or things can fall apart (as in normal c++). On a related issue I have also added "SmartPtr_Cast" which allows you to cast a smart pointer to a pointer of a different type. Unfortunately it has to be a bit awkward as MSVC 6 doesn't cope well with template functions. Also both classes must be derived (directly or indirectly) from RefCount<> to ensure that the reference counting works. Matt P.S. All this is going on in the Develop-EssenceRead branch which will become 0.5-Beta at some stage. |