Posted by: Cirilo Meggiolaro | 11/22/2008

Tip of the day #39 – LoaderOptimizationAttribute class

The LoaderOptimizationAttribute defines an enumerator that is used by the CLR to optimize the way this application will be loaded.

A good scenario to use the attribute is when you want to share resources (not static members) between application domains. The usage may have a performance penalty but if you need to have a lot of instances running a faster code or a single instance running slightly slower you’d rather to have the single instance.

The attribute must be defined on the main method of the application and if defined on a method other than the entry point, the attribute will be ignored and no exception will be thrown.

The following options are available to define the attribute:

SingleDomain: If you choose this option the loader will not share internal resources between application domains.

MultiDomain: Tells the loader that internal resources must be shared between application domains.

MultiDomainHost: Choosing this option will make the loader to share resources only for strongly-named assemblies registered on GAC.

How to…

Define the attribute is straightforward like any other attribute. Just type one of the following options before your application main method signature

[LoaderOptimization(LoaderOptimization.SingleDomain)]
[LoaderOptimization(LoaderOptimization.MultiDomain)]
[LoaderOptimization(LoaderOptimization.MultiDomainHost)]

Advertisements

Responses

  1. Cirilo, when you say “internal resources” you mean memory and cpu, right?

    What´s the default attribute we have in ASP.NET? MultiDomain?

  2. Hi Fadachi, actually internal resources mean objects / data and so on.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: