简体   繁体   中英

what happens when we overwrite cv::Mat.data

What will happen when we manually add an address of a buffer in data attributes of a cv::Mat object, and later delete that buffer?

For example,

cv::Mat test;
test.data = (address of Buffer A);

what will happen to test.data when Buffer A is deleted?

Documentation: http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html

int rows, cols, type; // you need initialize them
void* data = (address of Buffer A)
cv::Mat test = cv::Mat(rows, cols, type, data); // according to documentation, test does not own data
cv::Mat copy = test.clone() // copy copies is a deep copy of test 

So since test does not own Buffer A, once it's delete, if you access test.data, it's UB. However, since copy is a deep copy, you can access copy.data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM