One, the CLR homestay
The. NET Framework is allowed at the top of the Windows platform. means that the. NET Framework must be built with technologies that Windows can understand. All managed modules and assembly files must use the Windows PE file format, and either the Windows EXE file or the DLL file
1,mscoree.dll (GASKET)
The ①clrcreateinstance function is implemented in the MSCorEE.dll file. The work of "shims" is to decide which version of the CLR to create (1.0, 2.0, 3.0 CLR code in the MSCorWks.dll file; version 4 in the Clr.dll file)
The ②clrcreateinstance function can return a ICLRMetaHost interface. The host application can call the GetRuntime function of this interface to specify the CLR version that is primarily created by the host. The shim then loads the required version of the CLR into the host's process
2,iclrruntimehost can do the following things
① set up a host manager. The CLR host wants to participate in decisions that involve the following operations: memory allocation, thread scheduling/synchronization, and assembly loading. The host can also declare that it wants to get notifications about garbage collection start and stop and specific operation timeouts
② gets the CLR manager. Tells the CLR to block the use of certain classes/members. In addition, the host can distinguish which code can be debugged, which cannot, and which method the host should call when a particular event (such as an AppDomain unload, CLR stop, or stack removal exception) occurs
③ initializing and starting the CLR
④ loading assemblies and executing code in them
⑤ stops the CLR, prevents any more managed code from running in Windows process
Second, the AppDomain
An AppDomain is created when the CLR COM server is initialized. An AppDomain is a logical container for a set of assemblies. The first AppDomain created when CLR is initialized is called the default AppDomain, which is destroyed only when the Windows process terminates
Specific features of the 1,appdomain
① an AppDomain code cannot directly access an object created by another AppDomain's code.
After the code in an AppDomain creates an object, the object is "owned" by the AppDomain. In other words, its lifetime cannot exceed the AppDomain that created it all the code. The code in one AppDomain accesses an object from another AppDomain and can use only "marshal by reference" or "marshal by value". This forces the creation of clear segmentation and boundaries, because code in one AppDomain cannot directly reference objects created by code in another AppDomain. This isolation makes it easy for the AppDomain to unload from the process without affecting the code that other AppDomain is running
②appdomain can be uninstalled
The CLR does not support unloading a particular assembly from the AppDomain, but can tell the CLR to unload an AppDomain, thereby unloading all the assemblies currently contained in the AppDomain
③appdomain can be individually protected
After the AppDomain is created, a permission set is applied that determines the maximum permissions that are granted to assemblies running in the AppDomain, because such permissions exist, so that when the host loads some code, it guarantees that the code does not break (or read) Some of the important data structures used by the host itself
④appdomain can be configured separately
When the AppDomain is created, it associates a set of configuration settings. These settings primarily affect how the CLR loads assemblies in the AppDomain, design search paths, version binding redirection, shadow copy, and loader optimizations
2,windows process
Neutral AppDomain:
MSCorLib.dll contains System.object,system.int32 and all other types that are inseparable from the. NET Framework
All the types of objects in the loader heap, and all native code generated for JIT compilation defined by those types, are shared by all the AppDomain in the process
The neutral AppDomain cannot be unloaded unless the Windows process is terminated
CLR Homestay and AppDomain