RE: [Boost-users] Re: Using shared_ptr across shared library boun dary
David Abrahams wrote:
"Jim.Hyslop"
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)
participants (1)
-
Jim.Hyslop