Ansu Ansu - 2 months ago 31
C++ Question

what happens when we overwrite

What will happen when we manually add an address of a buffer in

attributes of a
object, and later delete that buffer?

For example,

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

what will happen to
Buffer A
is deleted?



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, it's UB. However, since copy is a deep copy, you can access