tailieunhanh - Expert C++/CLI .NET for Visual C++ Programmers phần 10

Kêu gọi Vứt bỏ và một finalizer trên cùng một đối tượng có khả năng sẽ kết thúc để làm sạch hai lần, và sẽ còn tiêu cực ảnh hưởng đến hiệu suất. Như bạn có thể thấy trong các mẫu mã trước đó, trình biên dịch ghi đè lên hệ thống:: Đối tượng:: Hoàn thiện. nếu thực sự là thông qua, và chức năng quyết toán | 292 CHAPTER 12 ASSEMBLY STARTUP AND RUNTIME INITIALIZATION called by _CorDllMain. In the following explanations I will call this entry point the mixed-code DLL s native entry point. The mixed-code DLL s native entry point is managed in the CLR header of an assembly. The following command line can be used to show the CLR header of the mixed-code dumpbin clrheader If you execute this command you will see the following output Microsoft R COFF PE Dumper Version Copyright C Microsoft Corporation. All rights reserved. Dump of file File Type DLL clr Header 48 cb runtime version 31D0 10 flags 3480 RVA size of 13EC entry point 100013EC 0 0 RVA size of 0 0 RVA size of 0 0 RVA size of 6650 18 RVA size of 0 0 RVA size of 0 0 RVA size of MetaData Directory Resources Directory StrongNameSignature Directory CodeManagerTable Directory VTableFixups Directory ExportAddressTableJumps Directory ManagedNativeHeader Directory The mixed-code DLL s native entry point that the linker has chosen for is __DllMainCRTStartup. As discussed in the context of native DLLs this is the function that is responsible for initializing and uninitializing the CRT. Due to this function call the global variable in is initialized. Furthermore DllMainCRTStartup forwards calls to DllMain which can be used by programmers to extend the native initialization and uninitialization. The next section discusses restrictions for DllMain in mixed-code assemblies. Custom Startup Logic and Load-Time Deadlocks DllMain in native as well as mixed-code DLLs must be implemented with special care. If you do not follow certain rules a deadlock can occur while a DLL is being loaded. DllMain is called either directly or indirectly via the DLL s PE entry point. Before calling the PE entry point of a DLL the operating system s image loader acquires a special critical section with the famous name loader lock. This loader lock can affect the PE entry point itself as well