Search code examples
c++refactoringshared-ptrsmart-pointers

Refactoring code to use Boost shared pointers


I wrote a project using normal pointers and now I'm fed up with manual memory management.

What are the issues that one could anticipate during refactoring?

Until now, I already spent an hour replacing X* with shared_ptr<X> for types I want to automatically manage memory. Then I changed dynamic_cast to dynamic_pointer_cast. I still see many more errors (comparing with NULL, passing this to a function).

I know the question is a bit vague and subjective, but I think I can benefit from experience of someone who has already done this.

Are there some pitfalls?


Solution

  • There is a tool that tries to automatically convert to smart pointers. I've never tried it. Here is a quote from the abstract of the following paper: http://www.cs.rutgers.edu/~santosh.nagarakatte/papers/ironclad-oopsla2013.pdf

    To enforce safety properties that are difficult to check statically, Ironclad C++ applies dynamic checks via templated “smart pointer” classes. Using a semi-automatic refactoring tool, we have ported nearly 50K lines of code to Ironclad C++