[Qt-interest] implicitly shared container iterators
Thiago Macieira
thiago at kde.org
Mon May 3 15:52:03 CEST 2010
Em Segunda-feira 03 Maio 2010, às 09:33:58, amulya rattan escreveu:
> Guys,
>
> Knowing that QHash is a implicitly shared class and if i do something like:
>
> QHash<QString, QThread*>::iterator it; // non-const iterator
> for (it = _loggers.begin(); it != _loggers.end(); ++it)
After this line above, the _loggers container is no longer shared.
You called two non-const methods above (begin() and end()), which cause the
container to atomically detach.
> {
> if (it.value())
> delete it.value();
>
> it.value() = NULL;
> }
> _loggers.clear();
>
> i believe it will create deep copy of items in hash. In that case, after i
> do delete it.value(), would there be dangling pointers of QThread(because
> of deep copy)?
> Can someone confirm this?
Yes. If any other variable was sharing the same contents of the _loggers hash,
it will now contain dangling pointers.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100503/45ce8868/attachment.bin
More information about the Qt-interest-old
mailing list