views:

364

answers:

1

I am writing a Qt application that has to handle big QImage s. QImage uses implicit sharing, which means it reference counts an internal data pointer. Whenever the refcount is > 1 the object counts as "shared" and any even only potentially data modifying call issues a deep copy of the image data.

In short: I don't want deep copies to happen.

I make a number of calls like setPixel(), bits() etc. that can trigger a copy. The documentation sometimes reads as if certain calls would always trigger a deep copy (detach call) even if I try my hardest to keep the refcount at 1. Like here: QImage::setPixel()

So I want to know:

  1. Is the doc only formulated a bit clumsily and these calls are reliably copying only shared objects (as in refcount > 1)?
  2. Can I ask an object what it's current refcount is, for debugging reasons and the like?
  3. Can I force Qt not to implicitly share specific objects/instances (<- well here my educated guess is "no")
+1  A: 
  1. Operations that could modify the shared instance will detach. setPixel detaches.
  2. Try QImage::isDetached() which does a return d && d->ref == 1;. By using a debugger, you can get to the actual refcount.
  3. Other than passing by reference/shared pointer no.
rpg
Damn. They didn't even document this... Thx! Thx too for reminding me that this is open source and I just have to have a look at it!
AndreasT