mirror of https://github.com/ARMmbed/mbed-os.git
Cleanup description
parent
2608478e87
commit
ac79b007d0
|
@ -32,31 +32,33 @@
|
||||||
* @code
|
* @code
|
||||||
* #include "platform/SharedPtr.h"
|
* #include "platform/SharedPtr.h"
|
||||||
*
|
*
|
||||||
* struct MyStruct { int a; };
|
* void test() {
|
||||||
|
* struct MyStruct { int a; };
|
||||||
*
|
*
|
||||||
* // Create shared pointer
|
* // Create shared pointer
|
||||||
* SharedPtr<MyStruct> ptr( new MyStruct );
|
* SharedPtr<MyStruct> ptr( new MyStruct );
|
||||||
*
|
*
|
||||||
* // Increase reference count
|
* // Increase reference count
|
||||||
* SharedPtr<MyStruct> ptr2( ptr );
|
* SharedPtr<MyStruct> ptr2( ptr );
|
||||||
*
|
*
|
||||||
* ptr = NULL; // Reference to the struct instance is still held by ptr2
|
* ptr = NULL; // Reference to the struct instance is still held by ptr2
|
||||||
*
|
*
|
||||||
* ptr2 = NULL; // The raw pointer is freed
|
* ptr2 = NULL; // The raw pointer is freed
|
||||||
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* It is similar to the std::shared_ptr class introduced in C++11,
|
* It is similar to the std::shared_ptr class introduced in C++11,
|
||||||
* however this is not a compatible implementation (no weak pointer, no make_shared, no custom deleters, etc.)
|
* however this is not a compatible implementation (no weak pointer, no make_shared, no custom deleters, etc.)
|
||||||
*
|
*
|
||||||
* Usage: SharedPtr<class> POINTER(new class())
|
* Usage: SharedPtr<Class> ptr(new Class())
|
||||||
*
|
*
|
||||||
* When POINTER is passed around by value the copy constructor and
|
* When ptr is passed around by value the copy constructor and
|
||||||
* destructor counts the number of references to the original object.
|
* destructor manages the reference count of the raw pointer.
|
||||||
* If the counter reaches zero, delete is called on the object pointed to.
|
* If the counter reaches zero, delete is called on the raw pointer.
|
||||||
*
|
*
|
||||||
* To avoid loops, "weak" references should be used by calling the original
|
* To avoid loops, "weak" references should be used by calling the original
|
||||||
* pointer directly through POINTER.get().
|
* pointer directly through ptr.get().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
Loading…
Reference in New Issue