I think you've misunderstood the purpose of the attribute.

All that this attribute does is shares JITed code across appdomains.

It does *not* share state.  In particular, each appdomain will get its
own set of static member variables.  It's only code that gets shared.
This is pretty similar to the way that the executable code pages in a
Win32 DLL get shared - the same physical page of memory may be mapped
into multiple processes, but this is just an optimization; the logical
model the programmer sees is that the DLL is loaded into each process
separately and independently.

Just like Win32 processes, AppDomains are always logically separated
even with MultiDomain loader optimization.  The only reason they let you
control this setting is that there is a trade-off to be made in the JIT:
the JIT can compile code that can be used across all the appdomains in a
process (just like a DLL can be mapped into multiple processes in
Windows).  But it has to generate slightly slower code to do this.  The
CLR has no way of knowing in general what the right trade-off is - if
you never plan to create any new AppDomains, generating shareable code
is the wrong thing to do because you never get to benefit from the
shareability, but you pay the overhead. On the other hand, if you *are*
creating AppDomains, and the same same components are being used in all
of them, then generating shareable code is likely to be the right thing
to do because the reduced memory overhead is likely to outweigh the
slightly more complex code that the JIT compiler generates.

The CLR has no way of working out what your intentions are up front,
hence the availability of the attribute to give it a hint.

But this is something that only makes sense at a per-process level - a
given program is probably either going to create appdomains or not.  A
DLL might not be in a position to know this.

But the main point is that if your aim is to share things like mainframe
connections, this attribute is not going to be of any use.


-- 
Ian Griffiths
DevelopMentor

> -----Original Message-----
> From: Sanchetia [mailto:[EMAIL PROTECTED]
> 
> I have used [LoaderOptimization(LoaderOptimization.MultiDomain)]
> attribute in service application which creates an EXE. But Where
should i
> use this attribute if I'm creating an Utility DLL. This DLL holds
> expensive
> connections to mainframes and other common processing logic which
needs to
> be shared for multiple appdomains (may be multiple host).

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

Guerrilla ASP.NET, 10 Nov 2003 in London and 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnet

Guerrilla .NET, 8 Dec 2003, in Los Angeles
http://www.develop.com/courses/gdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to