Boost logo

Glas :

Re: [glas] Reference counting?

From: Andreas P. Priesnitz (priesnit_at_[hidden])
Date: 2007-10-12 13:42:54

On Fri, 12 Oct 2007, Karl Meerbergen wrote:

> Do you see (other) situations where the storage of a reference could create
> overhead?

You might want to create views recursively (view into a view into a ...
container), for instance when modeling divide-and-conquer-algorithms
like quicksort that way.

In such cases, the number of views may have the same order of magnitude as
the number of container elements. Thus, the overhead for the reference
count would become significant. (and unnecessary)

(BTW: There is as well an increase in run time by creating, initializing,
incrementing, decrementing, checking, and deleting the counter.)

> As for smart pointers, we can have different views. A view could take
> ownership of the container (as for an auto_ptr, e.g.). The reference count
> would not be needed and this would make people happy who use small vectors.
> More important, I think, is the issue about the assignment operator and the
> copy constructor.
> Currently, the copy constructor makes a shallow copy for all views and
> expression objects, while the assignment operator is a deep copy. This looks
> like a conflicting situation. UBlas does the same I think. What about MTL?
> I am not very keen on giving up the deep copy concept of w = v. Does anyone
> have an interesting idea?

As you say, different kinds of ``smart views'' could coexist. In my
understanding, w = v should be overloaded to perform either deep or
shallow, depending on the way(s) w and v are referencing their data.

But the straightforward implementation - to define for any container/view
proper assignments from any other kind of view - is likely to cause a
considerable amount of (probably boilerplate) code.

The very interesting question would then be if and how one can express
this overload generically, as the choice of copy concept depends merely on
the kind of reference, not on the kind of data.