Revision history [back]

Does Mat::create() reallocate when new size is smaller?

Say I have an allocated cv::Mat img of size 100x100. Now I call img.create(50,50,img.type()).
Since the type is the same, there is, obviously, enough memory already allocated, and all that's needed is to set a proper "ROI" on the existing Mat.

Does create() actually do this, or does it release and re-allocate since the size is different (50x50 vs. 100x100)?

Does Mat::create() reallocate when new size is smaller?

Say I have an allocated cv::Mat img of size 100x100. Now I call img.create(50,50,img.type()).
Since the type is the same, there is, obviously, enough memory already allocated, and all that's needed is to set a proper "ROI" on the existing Mat.

Does create() actually do this, or does it release and re-allocate since the size is different (50x50 vs. 100x100)?

An std::vector<> uses the same stratgy. You can resize() it to 0, but it will still keep the internal buffer available so that growing again later, e.g. with push_back() does not reallocate. The same thing could be done with ROIs.