我讀了OpenCV的教程和它下面說一下OpenCV的形象holder類(CV :: MAT):如何通過引用返回對象?
The cv::Mat class implements reference counting and shallow copy such that when an image
is assigned to another one, the image data (that is the pixels) is not copied, and both images
will point to the same memory block. This also applies to images passed by value or returned
by value. A reference count is kept such that the memory will be released only when all of the
references to the image will be destructed.
我在那說This also applies to images passed by value or returned.
部分specficially感興趣怎麼可能指向當它通過值傳遞相同的內存塊?我覺得這與重載=
運營商有關。但它表示,即使圖像被返回,它也只會返回一個指向同一個內存塊的圖像,而不會創建一個新的圖像。我不明白他們是如何實現這一點的。
但這裏是我明白:
按值由於通和恢復的圖像做出新的圖像共享相同的內存塊,它是有道理的實現引用計數。
但是,你能解釋一下如何共享內存塊,即使當一個對象被返回或通過值傳遞?