Hi,

On Tuesday, April 24, 2012 22:51:34 James Turner wrote:
> Okay, I guess I was assuming I can use SGreferenced the same way I use
> release/retain in Cocoa, or addRef/decRef in COM/XPCOM. But it seems as if
> this is not the case, from looking at your commit - I can't use
> SGreferenced as a virtual base, and I have to make the delete call by hand.
> 
> I guess this is to avoid virtual method overhead on SGreferenced?
Yes.

SGReferenced should exactly *not* contain any virtual table. This is supposed 
to be the helper class for reference counting, but it should be as lightweight 
as possible. Imagine we want at some time have a variable size mathematical 
vector container that works with a copy on write semantics, I definitely want 
to use SGReferenced there and have no vtable at all.

If you want something that you can just use a general base class for 
heavyweight stuff, invent a class derived from SGReferenced or better 
SGWeakReferenced that introduces this vtable stuff. And since we are looking 
then for something more heavy, I would tend to use SGWeakReferenced as base 
class for an SGObject 

class SGObject : public SGWeakReferenced {
public:
        virtual ~SGObject() {}
}

The weak referenced class provides the ability to have weak pointers to such a 
WeakReferenced derived class. That are pointers that know about when the last 
reference to the instance it points to is deleted and provides a 
SGSharedPtr<T> SGWeakPtr<T>::lock() method that atomically and thread safe 
returns either a valid shared pointer to the still alive object or a null 
pointer since the objects reference count was already zero and the object is 
at least being deleted or already dead.

If you want the destructor protected, I need to backport something more from 
OpenRTI and stuff to simgear.

What about the mentioned problems? Better? Worse?

Mathias

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to