Question

Can multiple AppDomains be used to insulate memory in unmanaged dll too? Just to clarify, if I have an unmanaged dll using some internal static global variable, what will happen if I load that unmanaged dll in different appdomains? Can I safely suppose the dll will be loaded in different address spaces so they have all its own copy of the shared data?

Était-ce utile?

La solution

No, that's not possible. AppDomains are purely managed concept. Unmanaged DLL state is process-wide and there can be only one copy of the DLL loaded. A possible hack is to create copies of the DLL file with different names. It however scales very poorly and the pinvoke is nasty, having to write delegates and use LoadLibrary + GetProcAddress to bind them.

The cleaner alternative is to use separate helper processes that loads the DLL. Talk to them with an interop mechanism like WCF.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top