Next: , Previous: Strings, Up: Top


8 Smart Pointers

Smart pointers are used extensively in Aspell to simplify memory management tasks and to avoid memory leaks.

8.1 CopyPtr

The CopyPtr class makes a deep copy of an object whenever it is copied. The CopyPtr class is defined in copy_ptr.hpp. This header should be included wherever CopyPtr is used. The complete definition of the object CopyPtr is pointing to does not need to be defined at this point. The implementation is defined in copy_ptr-t.hpp. The implementation header file should be included at a point in your code where the class CopyPtr is pointing to is completely defined.

8.2 ClonePtr

ClonePtr is like copy pointer except the clone() method is used instead of the copy constructor to make copies of an object. If is defined in clone_ptr.hpp and implemented in clone_ptr-t.hpp.

8.3 StackPtr

A StackPtr is designed to be used whenever the only pointer to a new object allocated with new is on the stack. It is similar to the standard C++ auto_ptr but the semantics are a bit different. It is defined in stack_ptr.hpp — unlike CopyPtr or ClonePtr it is defined and implemented in this header file.

8.4 GenericCopyPtr

A generalized version of CopyPtr and ClonePtr which the two are based on. It is defined in generic_copy_ptr.hpp and implemented in generic_copy_ptr-t.hpp.