I've just commited a Reference counted template (with pointer semantics)
to the refcount branch on devel's squid3 module.
I haven't written the programmers guide doc's for this yet, so I'll note
them here:
To 'refcountise' a class, make it inherit from the Refcountable template
class ie:
===
class SomeClass :public RefCountable<SomeClass> {
public:
void deleteSelf() {delete this;}
};
===
You must define deleteSelf() as listed, because operator delete is
static, and thus MemPools don't work nicely with delete unless we use a
virtual method (which deleteSelf() is).
Then, create a user typedef to act as the pointer:
===
typedef RefCount<SomeClass> SomeClassPointer;
===
Now, in user code, you simply pass around
SomeClassPointer foo.
To initialise a new heap/mempool allocated object:
===
SomeClassPointer aPointer (new SomeClass);
===
When aPointer goes out of scope, the references will be decremented, and
when nothing references the object, it's deleteSelf() method will be
called.
Finally, we can only use this in classes that call the destructor at
some point, to be sure that SomeClassPointer objects go out of scope.
It's trival to make a cbdata class call the destructor, and I'll
document that in an email to this list before commiting the refcount
code to HEAD.. We can also convert cbdata classes to refcounted where
appropriate (which may be everywhere, but that is a different
discussion). It's also possible (as a transition strategy) to have
CBDATA's SomeClassPointers, but that may not be needed so I won't code
it up until it is :}).
I'd like to bring this into HEAD very soon, so:
Eugene, can you see if the test (in the test-suite) program passes for
the refcounted template? I want to be sure it will work on your
platform. Likewise, Guido, can you do the same?
I'm going to try the sunos compiler on sourceforge now.
Rob
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:18:38 MST