RV: RE: New shared pointer

Thiago Macieira thiago at kde.org
Sat Sep 10 00:38:43 BST 2005


Ignacio Castaño wrote:
>I think that the kind of shared pointer that you propose has a couple of
>problems. It adds an additional indirection and a memory allocation for
> the intermediate shared object. It's also error prone. Imagine that you
> have an object and its owner references it through your shared pointer.
> Then you pass a regular pointer to the shared object to the exiting
> API. Then the object is retrieved by some other object that uses a
> shared pointer to reference it too, but now you have two shared objects
> pointing to the same one. When the first reference is destroyed, the
> object goes away, leaving a dangling pointer. boost::shared_ptr has
> exactly the same problems.

You're not supposed to do that. The solution is really simple: do NOT mix 
dumb pointers with smart pointers.

However, the extra indirection is unavoidable unless your object has the 
refcount itself and that's exactly what Frerich is trying to avoid.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

4. And æfter se scieppend ingelogode, he wrát "cenn", ac eala! se 
rihtendgesamnung andswarode "cenn: ne wát hú cennan 'eall'. Ástynt."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050909/e8bc1cd6/attachment.sig>


More information about the kde-core-devel mailing list