Boost logo

Boost Users :

From: Jim.Hyslop (Jim.Hyslop_at_[hidden])
Date: 2004-03-12 09:08:32


David Abrahams wrote:
> "Jim.Hyslop" <Jim.Hyslop_at_[hidden]> writes:
> > It's been my experience
> > (with Visual Studio, at least) that allocating memory in one DLL and
> > deallocating it in another leads to problems. Sometimes it doesn't
> > go noticed, but when it does, it's really noticeable.
>
> The library cleverly avoids that, provided the first shared_ptr to
> take ownership of the memory does so in the same DLL where the object
> was allocated.
Huh - whaddya know; I just tried it with this program:

int main()
{
    boost::shared_ptr< T > t = CreateT();
    t.reset();
    T * tptr = CreateRawT();
    delete tptr;
}

where CreateT and CreateRawT are exported from a DLL (and do the obvious
thing). 't.reset()' works OK, but 'delete tptr' asserts on an invalid heap
pointer. I'll have to study the shared_ptr implementation to see how it
avoids this problem.

-- 
Jim Hyslop
Senior Software Designer
Leitch Technology International Inc. (http://www.leitch.com)
Columnist, C/C++ Users Journal (http://www.cuj.com/experts)

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net