Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The auto_ptr<> template has a number of issues, that make it unsuitable for a range of applications.

However, the cv::Ptr<> class is a full-fledged smart-pointer template, similar to boost::shared_ptr<>. You can use it safely in containers, and with some care and limitations, across threads.

Here is a more detailed explanation on smart pointers

http://answers.opencv.org/question/535/is-there-penalty-for-reference-counting-in-mat/#538

The auto_ptr<> template has a number of issues, that make it unsuitable for a range of applications.

However, the cv::Ptr<> class is a full-fledged smart-pointer template, similar to boost::shared_ptr<>. You can use it safely in containers, and with some care and limitations, across threads.

Here is a more detailed explanation on smart pointers

http://answers.opencv.org/question/535/is-there-penalty-for-reference-counting-in-mat/#538

Update on thread safety

(Copied from boost library docs - cv::Ptr<> and boost::shared_ptr<> are very similar in construction and usage)

shared_ptr objects offer the same level of thread safety as built-in types. A shared_ptr instance can be "read" (accessed using only const operations) simultaneously by multiple threads. Different shared_ptr instances can be "written to" (accessed using mutable operations such as operator= or reset) simultaneosly by multiple threads (even when these instances are copies, and share the same reference count underneath.)

Any other simultaneous accesses result in undefined behavior.