[Mono-dev] Creating AppDomains From Embedded Mono

Paolo Molaro lupus at ximian.com
Wed Jan 11 11:34:27 EST 2006

On 01/11/06 Jim Purbrick wrote:
> That gets me a MonoAppDomain*, which I can presumably
> use to call AppDomain.Load(Byte[]) to load a script's
> assembly, which will be unloaded (along with JIT
> output etc.) when I call unloadDomain?
> How do I turn the MonoAppDomain in to a MonoDomain
> required by mono_object_new, mono_string_new etc.?
> That is what my intermediate managed assemblies were
> doing: executing an assembly in the new domain which
> would call mono_domain_get() to get me a MonoDomain*
> for the new MonoAppDomain.

I think your approach was fine, using mono_domain_get() in an icall.
The suggestion to declare a struct similar to MonoAppDomain
in your own code will likely just result in crashes later on when we'll
change it.
We can add a function that returns the MonoDomain from an MonoAppDomain
object to make things simpler if you think it would help.
The embedded API currently is not well defined or entirely exposed to
create and switch between appdomains: I suggest doing that in helper
methods in managed code.

> Do I even need a MonoDomain* for the new
> MonoAppDomain? At the moment I try to allocate any
> objects used by a script in the AppDomain that I
> loaded the script's assembly in to, but I suppose I
> could allocate the other objects in the root domain.
> Would there be any problems doing this? My concern
> would be that the root domain would end up loading the
> script's assembly which I then couldn't unload.

Currently objects can't be leaked from one appdomain to another, so
expose to an appdomain only objects created inside it.


lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better

More information about the Mono-devel-list mailing list