Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-09-04 00:39:50


Philippe A. Bouchard wrote:

> Larry Evans wrote:
>
> [...]
>
>>>bool is_on_data(void * p); // Confirm p is address on data segment
>>>bool is_on_stack(void * p); // Confirm p is address on stack segment
>>>bool is_on_heap(void * p); // Confirm p is address on heap segment

[...]

>>>struct placed_ptr_header
>>>{
>>> int m_count;
>>> void * m_owner; // Could point to stacked candidate for
>>> destruction
>>>};

[...]

>> What if remainng placed_ptr is ALSO on stack?
>
> m_owner should be the one who allocated the object primarily. This is the
> important part, forget the previous code... .. .. . .

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).

-- 
Philippe A. Bouchard

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