[Tdg] Reference Counting

Wesley Smith wesley.hoke at gmail.com
Wed Aug 22 13:42:43 PDT 2007


> Can you qualify this? Do you mean, no data members are added?
> Do you mean, no member functions are added?

> If its not complex, why use a template class? I disagree that templates don't add complexity. At the very least, they add conceptual complexity from the point of view of the novice user. I look at a template class, and I wonder, "why was this done?". If its a simple situation, I'd favor a solution that didn't use templates. Why are templates necessary here?

Yes.  No member functions are added unless they're in the super class.
 No data members are added unless they're in the super class.  The
point of using templates is to make things completely conifigurable
(like allocation and threading models) without having to have the
source.  It's just a parameter to class instantiation from the
template and is a good way to parametrize a class with many deign
choices like ManagedObject.

For example:

ManagedObject<class AllocPolicy, class Threading Policy, class
SmartPointerPolicy>

could be created as follows:

ManagedObject<MemoryPoolPolicyClass, LockFreePolicyClass,
InstrusivePointerPolicyClass>

When you have templates like this you don't write them out explicitly
except once and from then on you use a typedef.  Then end-user never
has to know about this unless they want to thus saving the theoretical
"novice-user" from any supposed hardship"

typedef ManagedObject<MemoryPoolPolicyClass, LockFreePolicyClass,
InstrusivePointerPolicyClass> ManagedEvent;

then

class Event : public ManagedEvent
{

};


All this would add is 4 static functions overriding new, new[],
delete, delete[], 2 member functions for reference counting and one
data member for holding on to the reference count.  That ain't much
for a lot of behavior.  How could this possible scare of the novice
user who, being a novice, is not going to get into reparametrizing
ManagedObject anyway?


wes



More information about the Tdg mailing list