Boost logo

Boost Users :

From: Holger Grund (yg-boost-users_at_[hidden])
Date: 2003-08-20 11:17:55

"Drew" <drewtenn_at_[hidden]>,

> I originally posted this to,
> but they referred me back to here.
> Has anyone used boost's intrusive_ptr with Managed C++ extensions?
Mmh, not really. And it actually doesn't (currently ?) sound like a
compelling idea to me.

> I have a small project where the executable (managed) is linked to a
> native C++ dll.
> The code looks like:
> int _tmain()
> {
> boost::intrusive_ptr<Unmanaged> pUn = __nogc new Unmanaged();
> return 0;
> }
> when I exit out of main, boost::intrusive_ptr_release() throws an
> exception. The last known method called is:
> UnmanagedLib.dll!_CrtIsValidHeapPointer(...) Line 1807
This probably is not related to the managed extensions. It's more
likely that intrusive_ptr's dtor calls into the DLL to free the
which is only possible if both modules use the DLL version of
the CRT.

The message indicates that the pointer to be freed is bogus or more
likely from another heap. This is caused by a mismatch of the CRTs
used by the main program and the DLL. You could use the /MD[d]
option for both projects, so that both modules share a common CRT

I'd prefer to move intrusive_ptr_add_ref/release functions to the
program that uses the instrusive_ptr. Don't export these functions
from the DLL. Rather include these functions at build time.

That way you ensure, that operator delete is called from the
same module as operator new and everything should be fine.

> Unmanaged* pUm = new Unmanaged();
> delete pUm;
Yep. Same module. No problem.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at