equal
deleted
inserted
replaced
96 user of the pointer to explicitly @code{Unref()} the pointer when done. |
96 user of the pointer to explicitly @code{Unref()} the pointer when done. |
97 When the reference count falls to zero, the object is deleted. |
97 When the reference count falls to zero, the object is deleted. |
98 |
98 |
99 @itemize @bullet |
99 @itemize @bullet |
100 @item When the client code obtains a pointer from the object itself |
100 @item When the client code obtains a pointer from the object itself |
101 through object creation, or via QueryInterface, it does not have |
101 through object creation, or via GetObject, it does not have |
102 to increment the reference count. |
102 to increment the reference count. |
103 @item When client code obtains a pointer from another source (e.g., |
103 @item When client code obtains a pointer from another source (e.g., |
104 copying a pointer) it must call @code{Ref()} to increment the |
104 copying a pointer) it must call @code{Ref()} to increment the |
105 reference count. |
105 reference count. |
106 @item All users of the object pointer must call @code{Unref()} to |
106 @item All users of the object pointer must call @code{Unref()} to |
152 Please do not create such objects using @code{operator new}; create them |
152 Please do not create such objects using @code{operator new}; create them |
153 using @code{CreateObject()} instead. |
153 using @code{CreateObject()} instead. |
154 |
154 |
155 For objects deriving from @code{class RefCountBase}, or other |
155 For objects deriving from @code{class RefCountBase}, or other |
156 objects that support usage of the smart pointer class |
156 objects that support usage of the smart pointer class |
157 (in particular, the ns-3 Packet class), |
157 (in particular, the ns-3 Packet class does not derive from RefCountBase |
|
158 in order to avoid a vtable, but separately implements @code{Ref ()} and |
|
159 @code{Unref ()}), |
158 a templated helper function is available and recommended to be used: |
160 a templated helper function is available and recommended to be used: |
159 @verbatim |
161 @verbatim |
160 Ptr<B> b = Create<B> (); |
162 Ptr<B> b = Create<B> (); |
161 @end verbatim |
163 @end verbatim |
162 This is simply a wrapper around operator new that correctly handles |
164 This is simply a wrapper around operator new that correctly handles |
239 the return value from such a function call. If successful, the user can |
241 the return value from such a function call. If successful, the user can |
240 now use the Ptr to the Ipv4 object that was previously aggregated to |
242 now use the Ptr to the Ipv4 object that was previously aggregated to |
241 the node. |
243 the node. |
242 |
244 |
243 Another example of how one might use aggregation is to add optional |
245 Another example of how one might use aggregation is to add optional |
244 models to objects. For in |
246 models to objects. |
245 For instance, an existing Node object may have an ``Energy Model'' |
247 For instance, an existing Node object may have an ``Energy Model'' |
246 object aggregated to it at run time (without modifying |
248 object aggregated to it at run time (without modifying |
247 and recompiling the node class). An existing model (such as a wireless |
249 and recompiling the node class). An existing model (such as a wireless |
248 net device) can then later "GetObject" for the energy model and act |
250 net device) can then later "GetObject" for the energy model and act |
249 appropriately if the interface has been either built in to the underlying |
251 appropriately if the interface has been either built in to the underlying |