Reputation: 414
Starting with Boost release 1.53, shared_ptr can be used to hold a pointer to a dynamically allocated array. (http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/shared_ptr.htm)
Also, using shared_ptr has the benefit of allocator functions like boost::make_shared< int [] >(...);
Should I start using boost::shared_ptr instead of boost::shared_array when possible? it seems boost::shared_ptr can do most of the work boost::shared_array does.
Upvotes: 1
Views: 583
Reputation: 1382
Yes and one important benefit of using shared_ptr is that you no longer need to release the memory explicitly. The shared_ptr is a smart pointer and hence deallocates the memory by himself hence avoiding any memory leak. Also there is similar question exist on SO please visit the link Why use one vs the other: `boost::shared_array` VS `boost::shared_ptr<std::vector>`?
Upvotes: 0
Reputation: 18864
If the code is correct and working, I would not do the subject change.
If I had spare time and desire to do the change nevertheless, I would migrate to std::shared_ptr<T[]>
straight away.
Upvotes: 1