next up previous contents index
Next: 2.5 Configuration Up: 2.4 Memory Management Previous: 2.4 Memory Management   Contents   Index

2.4.1 Reference counting smart pointer

ns-3 provides a smart pointer class similar to Boost::intrusive_ptr. This smart-pointer class assumes that the underlying type provides a pair of Ref and Unref methods that are expected to increment and decrement the internal refcount of the object instance. We saw an example of this class in the query interface code above.

This implementation allows you to manipulate the smart pointer as if it was a normal pointer: you can compare it with zero, compare it against other pointers, assign zero to it, etc.

It is possible to extract the raw pointer from this smart pointer with the GetPointer and PeekPointer methods.

If you want to store a newed object into a smart pointer, we recommend you to use the MakeNewObject template functions to create the object and store it in a smart pointer to avoid memory leaks. These functions are really small conveniance functions and their goal is just is save you a small bit of typing.


next up previous contents index
Next: 2.5 Configuration Up: 2.4 Memory Management Previous: 2.4 Memory Management   Contents   Index
Tom Henderson 2007-08-15