[Development] QIntrusiveSharedPointer
Allan Sandfeld Jensen
kde at carewolf.com
Thu Aug 8 11:54:32 CEST 2019
On Thursday, 8 August 2019 11:33:04 CEST Philippe wrote:
> > No. When you call detach(), you're in a mutating function of the object
> > and you can assume that you're the only thread executing on a member
> > function of that thread, because if that's not the case, you're in UB
> > land. Only const methods are allowed to execute concurrently on the same
> > object. Mutators must get exclusive access.
>
> Absolutly right, but a method "isDetached()" which is const
> has no usefulness on its own, independently from a detach() procedure.
> This is the purpose of my orginal remark.
>
It has uses when combined with move-like semantics, when it is detached it
makes sense to perform in-place transforms on the "shared" data, but it if
isn't that would trigger two iterations over the data, first the detach
triggering a copy, and then the iteration over the data transforming it. If it
is shared, you can just iterate over the data read-only putting the result
into a new object. This is used many places with QImage.
Note though that QImage has a second use of isDetached() since QImage detach()
also copies user provided data even when not shared.
'Allan
More information about the Development
mailing list