|
Boost : |
From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-09-03 13:41:25
Philippe A. Bouchard wrote:
[...]
Correction. virtual ~T() doesn't mean the destructor is not trivial:
inline placed_ptr<T, simple_type>::destroy(T * p, __true_type const &)
{
...
for (list<void *>::iterator i = g.begin(); i != g.end(); ++ i)
{
free(p - (sizeof(ptr_header) + ptr_header::s_padding));
}
}
inline placed_ptr<T, complex_type>::destroy(T * p, __true_type const &)
{
...
free(dynamic_cast<void *>(p) - ...);
}
inline placed_ptr<T, simple_type>::destroy(T * p, __false_type const &)
{
p->~T();
free(p - (sizeof(ptr_header) + ptr_header::s_padding));
}
inline placed_ptr<T, complex_type>::destroy(T * p, __false_type const &)
{
...
free(dynamic_cast<void *>(p) - ...);
}
inline placed_ptr<T, simple_tree>::~placed_ptr()
{
if (m_ptr && ! -- get_count())
{
destroy(m_ptr, __type_traits<T>::has_trivial_destructor());
}
}
inline placed_ptr<T, complex_tree>::~placed_ptr()
{
if (m_ptr && ! -- get_count())
{
destroy(m_ptr, _type_traits<T>::has_trivial_destructor());
}
}
... and placement operator new (size_t, gc_type const &) could clean the
garbage in the heap if malloc() returns 0 also.
It seems you had the same idea Larry... I more reason not to not implement
it.
-- 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