Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-10813

Add possibility to disable thq qIsDetached check QCache<Key,T>::trim(int m)

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: P5: Not important
    • Resolution: Fixed
    • Affects Version/s: 4.5.1, 4.5.2, 4.5.3, 4.6.0, 4.6.1, 4.6.2
    • Fix Version/s: 5.0.0 Alpha
    • Labels:
      None
    • Commits:
      677cf76340f88e0fe51c1f75aa512b6d835414ca

      Description

      When a new Object is inserted into a full QCache, the function trim is called to remove some unused items out of the cache.
      There is a qIsDetached call that checks if the "payload" of T is shared by other objects outside the cache.

      This can lead to situations where the cache can not delete any objects at all. Therefore a property switch like setDeleteDetachedObjectsOnly(bool) would be nice.

      To clarify the problem here is a example:
      Imagine an ImageLoader Cache which uses two QCache objects:

      QCache<QFileInfo, QImage> rawImages;
      QCache<QPair<QFileInfo, EffectEnum>, QImage> manipulatedImages;

      The rawImagess cache contains plain, unmodified QImages just to avoid multiple reading and decoding of jpg files.
      The manipulatedImages contains some images exposed to some graphic effect(soften, noise, b/w, ....)

      So, the pseudocode would like this:

      QImage getManipulatedImage(QFileInfo file, EffectEnum fx) {
      QImage * result = manipulatedImages.object(QPair<file, fx>);
      if (result==NULL) {
      //image with effect fx is not cached, so we create it.
      result = rawImages(file);
      if (result==NULL)

      { result = new QImage(file.toAbsoluteFileName()); //raw image is also not available, so load it and store it rawImages.insert(file,QImage(*result)); //and insert it into the first cache. }

      //now apply the effect
      switch (fx)

      { FX_GRAY: result = grayScale(result); //grayscale image ... FX_NONE: default: //just no effect, simply the plain image. }

      manipulatedImages.insert(QPair<file,fx>, QImage(*result) ); //store the manipulated image in the second cache
      }
      return QImage(*result);
      }

      And now I come to the core of the problem:
      If FX_NONE is being used, then both cached contain the same QImage with the same shared data.
      In this situtation neither the first nor the second cache is willing to delete the image because it is still used by the other cache.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            rodal Samuel Rødal
            Reporter:
            joachimgelhaus Joachim Gelhaus
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes