Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-10-07 15:50:34


cppljevans_at_[hidden] wrote:

[...]

> If cycles can only be created in predicatable
> circumstances, or restrictions are placed on
> programming style, it may be possible to treat
> cycles as a whole, i.e. with a single reference
> count, and delete it automically with the count
> drops to zero.

Better example:

struct indicator
{
    long counter;
    indicator * p;
};

template <typename T>
    struct shifted_ptr
    {
        ...

        T * m_ptr;
        indicator * m_ind;
    };

Now, every time a pointer on the stack will refer to a newly allocated block
an "indicator" will be created. At first indicator::p will point to
indicator::counter of the same instance but it will refer to a different
counter if two groups are merged.

It is not easy to implement following the standards in an acceptable matter
but it is possible & I would like some help eventually.

*** The worse case scenario for its memory usage would be (very very
unlikely): ***
n -> number of pointees
m -> number of smart pointers living on the heap

extra_memory = 2 * m * sizeof(void *) + n * sizeof(long) + m *
sizeof(indicator)

*** The best case scenario (for 1 smart pointer on the stack = 1 group): ***
extra_memory = 2 * m * sizeof(void *) + n * sizeof(long) + sizeof(indicator)

*** Notes: ***
sizeof(long): represents the regular reference count for each pointee;
sizeof(indicator): represents the size of an indicator;
2 * sizeof(void *): represents the size of shifted_ptr<>.

Philippe


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