c++ - Difference between QSharedPointer and QSharedDataPointer? -
what difference between these 2 types of pointers? far can read, qsharedpointer can handle situation well, need qshareddatapointer?
from qt documentation qshareddatapointer
the qshareddatapointer class represents pointer implicitly shared object. qshareddatapointer makes writing own implicitly shared classes easy. qshareddatapointer implements thread-safe reference counting, ensuring adding qshareddatapointers reentrant classes won't make them non-reentrant. implicit sharing used many qt classes combine speed , memory efficiency of pointers ease of use of classes. see shared classes page more information.
example usage -
#include <qshareddata> #include <qstring> class employeedata : public qshareddata { public: employeedata() : id(-1) { } employeedata(const employeedata &other) : qshareddata(other), id(other.id), name(other.name) { } ~employeedata() { }
for qsharedpointer
the qsharedpointer class holds strong reference shared pointer qsharedpointer automatic, shared pointer in c++. behaves normal pointer normal purposes, including respect constness. qsharedpointer delete pointer holding when goes out of scope, provided no other qsharedpointer objects referencing it.
> qsharedpointer<myobject> obj = > qsharedpointer<myobject>(new myobject);
so, qshareddatapointer used make creating implicititly shared classes. whereas qsharedpointer reference counting smart pointer points classes.
edit
when reading memory management in qt?, found link http://labs.qt.nokia.com/2009/08/25/count-with-me-how-many-smart-pointer-classes-does-qt-have/. excellent discussion of different smart pointers qt has (current api has 8).
Comments
Post a Comment