Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-10-13 02:05:01

Hi Dave,

Dave Harris wrote:
> template<class Archive ar, class T>
> T *load_construct(Archive & ar, void * pt, unsigned int file_version)
> {
> T *t = new( pt ) T();
> try {
> ar >> *t;
> } catch (...) {
> t->T::~T();
> throw;
> }
> return t;
> }
> The signature has changed as well as the implementation. There is some
> question about the use of placement new here, in the cases where the user
> has class-specific operator new. This is a general issue. In my view
> boost, and/or the C++ standard, needs to evolve support for safe use of
> placement new.

Can I shamelessy take a free C++ lesson? ;-) I never used placement new, so
I'm not sure I understand the problem. Say, T has overloaded placement
operator new. Is the question how to delete the object? If exception is
thrown during construction, then the paired placement delete is
automatically called. The questions are:

1. Can the same paired placement delete be be used for destruction after the
object is created:

      T* t = ....
      T::operator delete(t);

2. Is the issue that if object is created in raw memory via placement new,
then if it's deleted by a program, the raw memory is never freed?

      T* t = ..... // does new(pt) T, where 'pt' could point to anything.
      delete t; // does nothing, causing memory leak if 'pt' was dynamically
                // allocated.



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