Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2002-09-04 07:30:43

Philippe A. Bouchard wrote:

>Philippe A. Bouchard wrote:

>What if instead we use this header:
>struct placed_ptr_header
> int m_count;
> int m_stacked; // Could count # of times it is referenced on stack
>m_stacked would be decremented each time a pointer allocated on the stack
>is destroyed or reset()ed. This counter could be spreaded all around the
>pointer diagram on the heap and could call free() when the pointer is the
>last one on the stack taking care of the object (stack or data segment).
Looks much better.

However, there are other problems:

1) These, let's call them "root" pointers (to avoid deciding
whether to call them stack of static), must be stored in some container in
available to the collector in order to do the collection.
The root pointer must also be removed from
same when m_stacked becomes 0. If map is used, that's a big time hit
when many
short-lived shared_ptrs are used (as is often the case). Greg had a faster

2) m_stacked will not be incremented for each placed_ptr in, e.g.:

vector<placed_ptr<T> > x1;
vector<vector<placed_ptr<T> > > x2;

because the "real" root pointers are those starting the vectors.

Boost list run by bdawes at, gregod at, cpdaniel at, john at