Boost logo

Boost Users :

From: Mark Storer (MStorer_at_[hidden])
Date: 2004-02-25 19:37:59


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;


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net