Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2002-07-17 08:06:56


"Philippe A. Bouchard" <philippeb_at_[hidden]> wrote in message news:ah3b6t$nah$1_at_main.gmane.org...
>
> > > And I'm curious to know if
> > > the compiler is not creating the object directly instead of creating a
> > > temporary, copying it and destroying it when optimizations are
> requested.
> >
> > Certainly not in all circumstances. For example, if the constructor reads
> configuration data from a file, it will be read twice. And of course, part
> of the convenience of shared_ptr is that it often makes it practical for
> classes to be noncopyable, which can save development time, depending on the
> nature of the class.
>
> Here is a draft version of what could remove copy constructors usages. It
> would require proper initialization from the user in this example. Besides
> the implicit reinterpret_cast<> in the constructor which shouldn't be there
> IMO, any thoughts?

Looking at the code, I don't follow how it is supposed to work. For example, consider the code:

squad_ptr<char> p(new char);

In this case, squad_ptr puts its use count in memory immediately following what was allocated for the character. This amounts to a buffer overrun, blowing past the block that the heap manager gave your program.


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