Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2003-10-13 12:21:00

In-Reply-To: <bmdir4$dn3$1_at_[hidden]>
ghost_at_[hidden] (Vladimir Prus) wrote (abridged):
> Can I shamelessy take a free C++ lesson? ;-)

I'm not the best person to give it to you. The problem was raised by David
Abrahams, and I see he has now posted a draft of a solution. To be honest
I am struggling to keep up with him :-)

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

It'll be freed, but in the wrong way.

    char *buf = operator new( sizeof(T) ); // Global new.
    T *pt = new(buf) T;
    // ...
    delete pt; // Class-specific delete.

If the class has overloaded non-placement operators, we will be calling
the class version of operator delete() but not the class version of
operator new(). This mismatch will lead to tears.

We can't control destruction here, so we need to call the class version of
operator new() as well - but there may not be one.

-- Dave Harris, Nottingham, UK

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