OpenCV中的Ptr解析
2013-11-15 16:36
288 查看
OpenCV里面的Ptr的定义如下:Template class for smart reference-counting pointers,即智能指针模板类。The Ptr<_Tp> class is a template class that wraps
pointers of the corresponding type. It is similar to shared_ptr that is part of the Boost library (http://www.boost.org/doc/libs/1_40_0/libs/smart_ptr/shared_ptr.htm) and also part of the C++0x standard.
This class provides the following options:
Default constructor, copy constructor, and assignment operator for an arbitrary C++ class or a C structure. For some objects, like files, windows, mutexes, sockets, and others, a copy
constructor or an assignment operator are difficult to define. For some other objects, like complex classifiers in OpenCV, copy constructors are absent and not easy to implement. Finally, some of complex OpenCV and your own data structures may be written in
C. However, copy constructors and default constructors can simplify programming a lot.Besides, they are often required (for example, by STL containers). By wrapping a pointer to such a complex object TObj to Ptr<TObj>,
you automatically get all of the necessary constructors and the assignment operator.
O(1) complexity of the above-mentioned operations. While some structures, likestd::vector,
provide a copy constructor and an assignment operator, the operations may take a considerable amount of time if the data structures are large. But if the structures are put into Ptr<>,
the overhead is small and independent of the data size.
Automatic destruction, even for C structures. See the example below with FILE*.
Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers can store only objects of the same type and the same size. The classical solution to
store objects of different types in the same container is to store pointers to the base class base_class_t* instead but then you loose the
automatic memory management. Again, by using Ptr<base_class_t>() instead
of the raw pointers, you can solve the problem.
cast pointer to another type
OpenCV中的智能指针Ptr模板类就是采用分离引用计数型的句柄类实现技术。
pointers of the corresponding type. It is similar to shared_ptr that is part of the Boost library (http://www.boost.org/doc/libs/1_40_0/libs/smart_ptr/shared_ptr.htm) and also part of the C++0x standard.
This class provides the following options:
Default constructor, copy constructor, and assignment operator for an arbitrary C++ class or a C structure. For some objects, like files, windows, mutexes, sockets, and others, a copy
constructor or an assignment operator are difficult to define. For some other objects, like complex classifiers in OpenCV, copy constructors are absent and not easy to implement. Finally, some of complex OpenCV and your own data structures may be written in
C. However, copy constructors and default constructors can simplify programming a lot.Besides, they are often required (for example, by STL containers). By wrapping a pointer to such a complex object TObj to Ptr<TObj>,
you automatically get all of the necessary constructors and the assignment operator.
O(1) complexity of the above-mentioned operations. While some structures, likestd::vector,
provide a copy constructor and an assignment operator, the operations may take a considerable amount of time if the data structures are large. But if the structures are put into Ptr<>,
the overhead is small and independent of the data size.
Automatic destruction, even for C structures. See the example below with FILE*.
Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers can store only objects of the same type and the same size. The classical solution to
store objects of different types in the same container is to store pointers to the base class base_class_t* instead but then you loose the
automatic memory management. Again, by using Ptr<base_class_t>() instead
of the raw pointers, you can solve the problem.
cast pointer to another type
template<typename _Tp2> Ptr<_Tp2> ptr(); template<typename _Tp2> const Ptr<_Tp2> ptr() const;
OpenCV中的智能指针Ptr模板类就是采用分离引用计数型的句柄类实现技术。
相关文章推荐
- OpenCart之增强型博客(Blog)模块
- 《Linux命令行与shell脚本编程大全》 第二十四章 学习笔记
- org.apache.jasper.JasperException: java.lang.NullPointerException一个神奇的异常
- syslog(),openlog(),closelog()
- devcloud 基础架构
- Apparmor——Linux内核中的强制访问控制系统
- Quartz的监控和管理工具:quartz-monitor
- linux常见命令(grep,wc)
- linux查看端口占用
- 在tomcat5中发布项目时,用IP地址+端口不能访问项目,而用localhost加端口时可以访问成功
- linux常见命令(which,whereis,locate,find)
- 【第一弹】探索矩阵转换、透视投影、OpenGL矩阵存储及操作特性、法线的应用以及GLFrame的使用
- linux tar.gz zip 解压缩 压缩命令
- 俄罗斯方块shell 实现
- Apache Hadoop 2.0.2-alpha
- Apache Hadoop 2.0.2-alpha
- linux下tar命令解压到指定的目录
- centos6.4-x86_64bit 安装rabbitmq(做一下备忘)
- 一个网站是如何做宣传推广(三)?
- hadoop的节点间的通信