Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2002-07-30 13:26:44


> > What I meant is that not all dynamically-allocated objects are placed in a
> > ptr<>. Displacing the global new & delete forces the count to be
> allocated
> > every time new is called; for example, every node allocated by every
> > std::list<..> would then take up more memory than necessary.
>
> On the other hand it would be faster knowing this and it would help to
> implement the basic_string<> class. Convertions to ptr<char const []> would
> be easier to maintain also... It depends on the situation but I don't want
> to reinvent the wheel also.

You still haven't answered what is IMHO the killer objection to date to
(any version of) your proposal, which is its behavior in the presence
of multiple inheritance.

class X { int x; };
class Y { int y; };
class Derived: public X, public Y {};

The layout of Derived is going to be X::x followed by Y::y (or
vice-versa). If you do:

ptr<Derived> pd = new Derived (whatever syntax) ;
ptr<Y> py = pd;
ptr<X> px = pd;

one of py, px is going to point into the middle of the Derived object;
and then the imputed reference count location will be *wrong*. So
either you need to forbid ptr's to multiply-derived objects or forbid
conversions to base classes inside ptr's. Either of these is a pretty
serious price to pay, IMHO.

George Heintzelman
georgeh_at_[hidden]


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