curious
curious

Reputation: 1

Memory allocation for structures like Mat in OpenCV

I understand that Mat a = b just copies the reference of b to a, there is no separate memory allocated.

But in the following code:

VideoCapture cap(0);
Mat frame;

for(i = 0; i<10; i++)
    cap.read(frame);

In every iteration, the Mat variable is updated. So does that mean that new memory is allocated in every loop. If so, what happens to the memory allocated before? Is it destroyed or not? At the end of 10 iterations, is the memory used up in the system equal to 10*sizeof(Mat) or is the memory allocated to Mat frame overwritten every time we update A?

Upvotes: 0

Views: 550

Answers (1)

unxnut
unxnut

Reputation: 8839

In this instance, VideoCapture updates the frame and no new copy of Mat is created. Mat is overwritten in every iteration.

Upvotes: 2

Related Questions