shared lib: conversion-lib in Plasma
Aaron J. Seigo
aseigo at kde.org
Tue Jul 28 09:54:55 BST 2009
On Tuesday 28 July 2009, Petri Damstén wrote:
> Which I removed, since I can't see how it could work if Unit is KSharedPtr.
> Converter has UnitCategories which has Units. Category takes care of
> creating and deleting units. If Unit is deleted outside category (by
> KSharedPtr or otherwise) categories will fail. Values only have pointer to
problem is that this is very brittle. it means new units can never be
dynamically added/removed safely, but more importantly if the units are to be
cleaned up at some point (which i think they do, as noted in the previous
email) then handing around the same naked pointer amongst various classes is
just asking for a dangling pointer to appear somewhere.
since UnitCategory keeps a reference to the Unit in its two maps, if they
were KSharedPtrs instead they'd stay in reference until the UnitCategory went
away. the UnitCategory would then be in clear ownership of the Unit objects
and control their life-span.
 btw, all the calls to keys() and values() in UnitCategory really ought to
be changed to something else; both of those calls iterate through the
collections and create a whole new collection. having a simple collection
(e.g. a List or a Set) of KSharedPtr<Unit> would prevent all the calls to
values, for instance.
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA EE75 D6B7 2EB1 A7F1 DB43
KDE core developer sponsored by Qt Software
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 197 bytes
Desc: This is a digitally signed message part.
More information about the kde-core-devel