OpenCV Mat::operator= - does it support copy on write?

后端 未结 2 494
时光取名叫无心
时光取名叫无心 2020-12-19 06:38

From the OpenCV documentation, it appears that copying a matrix is done using a shallow copy, but when changing one of the copies, a copy is done.

The exact referenc

相关标签:
2条回答
  • 2020-12-19 07:00

    You can make a deep copy with Mat::copyTo(). E.g.

    Mat a(5,5,CV_32C1),b;
    a = 1;
    a.copyTo(b);
    a = 2;
    

    But no, Mat does not support copy-on-write. When you need to make a change to a without affecting b, you need to make a deep copy of a to b, and then modify a.

    0 讨论(0)
  • 2020-12-19 07:02

    It seems you misunderstood. "Before assigning new data, the old data is dereferenced via Mat::release" does not mean that when you write on a or b then a copy occurs. It means that when you type b=a, you lose the data that was in b.

    Long story short : copy on write is not supported.

    0 讨论(0)
提交回复
热议问题