RE: [Boost-users] shared_ptr/shared_array Question
I'd go with scoped_array<> by default, and only go with shared_array<> if you need to share OWNERSHIP of that array. This master/slave example doesn't give enough context to make the choice apparent. PS: There's a bug in your original code:
Master::~Master() { delete sl; }
If you use the [] version of new, you should use the [] version of delete: Master::~Master() { delete[] sl; } Otherwise, many implementations of 'delete' will only call the destructor of the first element in the array, and may or may not free up the entire block of memory. Some implementations may actually clean everything up properly, but I wouldn't count on it if I were you. --Mark Storer Software Engineer Cardiff Software #include <disclaimer> typdef std::disclaimer<Cardiff> Discard;
participants (1)
-
Mark Storer