From Apache OpenOffice Wiki
Revision as of 08:18, 11 July 2007 by Np
o3tl::heap_ptr<> - a Const-Transitive Smart Pointer Class
heap_ptr<> is a const-transitive, non-copyable, C++ smart pointer class.
- smart pointer: A class that holds a pointer to memory allocated on the heap. The destructor automatically deletes (deallocates) the memory.
- const-transitive: In
const heap_ptr<int> pX( new int(25) );not only pX is const, but also the integer value it points to. This is useful for member variables of classes, because if the class administrates the heap memory, it is normally part of its state.
- non-copyable: When copying pointers to heap-memory, there either must be a reference counting or the pointer must not be copyable to make sure, delete is called at the right time for the heap memory.
|Reference Document||Location (URL)|
|Product Requirement, RFE, Issue ID||IssueZilla 76768|
|Test case specification||Unit Tests in module o3tl/qa/test-heap_ptr.cxx|
|Coding Standards this class helps to match||http://wiki.services.openoffice.org/wiki/Cpp_Coding_Standards/GEN#RAII|
|Quality Assurance||Thorsten Behrensemail@example.com|
- Member data on the heap
- This class should be the default for class members that are pointers to heap memory and are not shared with other instances, but administrated only by one object. Plain pointers, std::auto_ptr<> and non const-transitive pointers should be replaced, when refactoring.
- RAII in function bodies
- It can be used in new code, when using RAII for heap memory within a function body.