Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-01-03 21:24:28


At the top of multi_array_ref.html it says:

    multi_array_ref does not own the data passed to it.

Then:

multi_array_ref& operator=(const multi_array_ref& x)
        Assignment operator. This performs a deep copy of the other
        array. Note that array dimensions must agree.

Who owns these data? The returned multi_array_ref?
Do some multi_array_ref own data?
Should the sentence at the top be qualified? E.g.

   multi_array_ref does not own the data passed to it
   in the constructor.

Related question:

Multi-dimensional arrays tend to be large (mega-bytes). On the other
hand, the copy constructor and the assignment operator perform deep
copies. Then, how would I code e.g. operator+()?

marray operator+(const marray& lhs, const marray& rhs) {
  marray result;
  // do the addition
  return result; // deep copy???
}

I guess I am asking if the std::vector-type copy semantics is useful
for multi_array. Have alternatives been considered?

E.g., the use of a shared_pointer inside multi_array, shallow copies
as the default, and an explicit member function
multi_array::deep_copy?
That way application writers using multi_arrays would have to worry
less about memory management/performance and the resulting code will
look more natural (multi_arrays as return values).

Ralf

P.S.: I wish there were a reference-counted sequence type in the STL
(the 1d equivalent of what I just proposed). Has this ever been
discussed by the C++ committee?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk