I have a C ++ application that makes heavy use of pointers to support fairly complex data structures. The application performs mathematical modeling on huge data sets (which can take up several GB of memory) and compiled using Microsoft Visual Studio 2010.
Now I am recycling an important part of the application. To reduce errors (dangling pointers, memory leaks, ...), I would like to start using smart pointers. A donation of memory or performance is acceptable if it is limited.
In practice, most classes are supported in large pools (one pool per class), and although classes can refer to each other, you can consider the pool as the owner of all instances of this class. However, if the pool decides to delete the instance, I do not want any of the other classes to still refer to the remote instance in order to have a dangling pointer.
In another part, I keep a collection of pointers to instances that are supplied by other modules in the application. In practice, other modules maintain ownership of the transferred instance, but in some cases the modules do not want to take care of the property and simply want to transfer the instance to the collection, telling it "now, manage it."
What is the best way to start implementing smart pointers? Simply changing pointers [in random order] using smart pointers does not seem right and probably does not deliver all (or any) of the benefits of smart pointers. But which method is better?
What types of smart pointers should be explored further? I sometimes use std :: auto_ptr to free locally allocated memory, but this seems to be fixed in C ++ 0x. Is std :: unique_ptr a better alternative? Or do I need to go to generic pointers or other types of smart pointers?
Question Replacing existing level pointers with smart pointers seems similar, but instead of asking how simple it is, I ask what the best approach is and what kind of smart pointers are best suited.
Thanks in advance for your ideas and suggestions.
c ++ architecture smart-pointers
Patrick
source share