Scott Stafford
Scott Stafford

Reputation: 44776

When can two .NET processes share DLL memory?

I have two ASP.NET websites that reference the same class llibrary. Currently we publish the site with two copies of the class library. Does this waste memory? Does the OS know the two copies of the file are the same and so can share memory for the code sections of the DLL? If I copied it into the GAC or another shared location such that it was only one physical file, would it map less total memory?

Upvotes: 1

Views: 706

Answers (2)

Hans Passant
Hans Passant

Reputation: 941227

This question starts off with the wrong premise, an ASP.NET DLL doesn't contain any code. Just data, IL and the assembly manifest. The jitter generates machine code from the IL, that code goes into the loader heap for the AppDomain. Private bytes of the process and not shared.

Getting one copy of the machine code that's generated from the IL is possible, you have to run Ngen.exe. It precompiles the IL and generates a native DLL, a .ni.dll that's stored in a GAC subdirectory. That code can be shared with only one copy of it in RAM.

Upvotes: 3

Daniel A. White
Daniel A. White

Reputation: 190897

A process and an app domain has to have it loaded into memory for it to function properly. App Domains and processes are sandboxed.

Upvotes: 0

Related Questions