GLib/GObject+C as the lingua franca?

Thiago Macieira thiago at kde.org
Wed Jul 30 22:29:45 BST 2008


nf2 wrote:
>Will the refcounter be inside QObject or inside the pointer-holding
> class?

QObjects don't have an internal reference counter. So the counter has to 
be outside.

I'm trying to make it so that QSharedPointer supports both pointers 
internal and external.

>Because in the latter case you would loose the refcount as soon as you
>just pass the pointer to a function or try to cast the pointer:
>
>QRefCountedPointer<A> a = new A();
>
>call_some_function(a.p);

call_some_function(a);

This is C++, we have cast operators :-)

>or
>
>QRefCountedPointer<B> = dynamic_cast<B*> a.p;

QSharedPointer<B> = a.dynamicCast<B>();
QSharedPointer<B> = qSharedPointerDynamicCast<B>(a);


In any case, if the object passes itself as pointers to other points (such 
as in a signal emission or in "return this"), then the reference counting 
has to be internal to the object. That's the only way to keep a 
consistent count.

Also be careful if any object that can be reference counted holds an 
object by reference counting. Eventually that may lead to cyclic 
reference counting.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080730/2b8700cf/attachment.sig>


More information about the kde-core-devel mailing list