Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Doubt related to Implicit Sharing

Doubt related to Implicit Sharing

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 869 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    Greetings.

    I'm working on a project using Qt and OpenCV.
    I'm using QStack in one of my classes and I read in the documentation about 'Implicit Sharing'.

    Well, although I think I understand almost everything, however there is an issue that I'm not entirely sure, and since I have been having some problems with the amount of memory available to an application or process, thought I'd clarify my doubt.

    Suppose you have a stack QStack<T> where 'T' is a type not belonging to Qt (specifically it is an image cv::Mat... although I think it is irrelevant to my problem).

    Assume also that the stack several images have been added, what happens if you run a statement like this:

    imgsStack = QStack cv::Mat ();

    What happens with the memory space occupied by the old stack of images? ... Is it free?

    I understand by 'Implicit Sharing', the space must be released, although I'm not entirely sure.

    Is the space occupied by each image cv::Mat is also released automatically or, on the contrary, I release myself manually?

    Thanks in advance for any responses and/or comments.

    Isaac Pérez
    Programming is understanding.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      If the memory of imgsStack is not referenced by ("shared with") another QStackcv::Mat variable, then yes, the cv::Mat is freed, assuming cv::Mat frees its memory properly in the destructor. And of course assuming, you're not using a QStackcv::Mat*. In that case, the memory of the pointer addresses (n*4 bytes) is freed, but not the memory the pointers point to (the actual cv::Mat data).

      With implicit sharing you don't have to take special care not to use more memory than necessary. It actually helps you to use less memory.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved