Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-09-03 17:04:29


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
>>
> The above would be os dependent. I don't think that's much of a problem
> since
> all the conservative methods used os dependent methods to delimit the
> stack and
> data segments. I'm guessing that a data segment is where static data is
> stored?

Yes.

>>
>>struct placed_ptr_header
>>{
>> int m_count;
>> void * m_owner; // Could point to stacked candidate for
>> destruction
>>};
>>
>>placed_ptr<T>::placed_ptr(...)
>>{
>> if (is_on_stack(this))
>>
> should ^ also have "|| is_on_data(this)"?

Yes.

>> {
>> get_owner() = this;
>> }
>> ...
>>}
>>
>>placed_ptr<T>::~placed_ptr()
>>{
>> if (m_ptr)
>> {
>> -- get_count();
>>
>> if (get_count() == 0)
>> {
>> m_ptr->~T();
>> free(m_ptr - ...);
>> }
>> else if (get_count() == 1 && get_owner() == this)
>>
> 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... .. .. . .

PS.: On 32 bits platforms it doesn't matter having
sizeof(placed_ptr_header) == sizeof(int) + sizeof(void *) because
BOOST_DATA_ALIGN == 8 == sizeof(placed_ptr_header).

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