How are system resources such as GDI resources managed in Windows NT?

  

#11 Floor score: 0 Reply to: 2006-04-29 08:37:18

Why is the GDI resource exhausted, to what extent? Exhausted? Data Recovery Training In order to answer this question, we observed the Windows Explorer's own task manager and found that when the program interface starts to confuse, the GDI object value of the process is 9999, then why does the interface become confusing after the GDI object reaches 9999? With this question, I found some information and simply learned how Windows manages GDI objects. Office software failure GDI objects are actually some data structures maintained by Windows systems. Based on stability and robustness, Microsoft hands over the management of all GDI objects to the object manager of the Windows system. Users can only manipulate these objects through the "handles" returned by the system. Graphics card failure In Windows 2000, the handle is actually a DWORD type value. The DWORD value is a 32-bit data, which is divided into two parts: Table Index and Uniqueness Identifier, which each occupy 16 bits. Therefore, in theory, every process in Windows can access GDI. The maximum value of the object is 64K. However, in Windows 2000, the maximum number of client handles is hard set to 16384 (16K); however, in Windows 2000, even if the maximum number of client handles is hard set to 16384, then why is the actual GDI object added to After 9999, the program interface began to confuse? It turns out that in Windows 2000, the maximum value of GDI objects per process is defaulted to 10000 - according to Microsoft data, the reason is set to 10000, in order to prevent the "Bad" program from allocating too many resources, therefore, when the GDI object After reaching 9999, the program can no longer create new GDI resources, so the program that uses the new resources to draw the interface every time is confusing. However, in Windows 2000 and later operating systems, the maximum value of GDI objects that each process can create can be reset by modifying the registry. In Windows 2000, the registry key is: HKEY_LOCAL_MACHINE\\ SOFTWARE \\Microsoft\\Windows NT\\CurrentVersion\\Windows"GDIProcessHandleQuota ". After setting the new value, after restarting the computer, the number of GDI objects that can be used per process in the system will become your newly set number. However, the above statement is not entirely correct! According to a SYBASE data display (?id=1019174), in Windwos2000, only the "GDIProcessHandleQuota" value can be fine-tuned. If the value exceeds 15000, the system becomes unstable. In fact, I tested it in Windows 2000. When the return value of the GetGuiResources function is 12288 (12K), I can't create a new GDI object, that is, a total GDI object in a process in Windows 2000. After the number reaches 12288, you can no longer create new GDI objects. So, in Windows 2000, the number of GDI objects that a process can create is independent of each process, or is it limited by the Windows operating system? To this end, I wrote a check program, which creates a specified number of BRUSH objects in batches, and counts the number of GDI objects in the process and the total number of GDI objects in the system. The running interface is as follows (the figure shows no, but nothing. The code for the total GDI object in the statistical system is as follows: int GetGDINumInSystem(void) { int nGDINums = 0; /* The sum of GDI objects of all processes */int nProcess = 0; /* Number of processes in the system */DWORD aProID[1024]; DWORD cbNeeded; ::EnumProcesses ( aProID, sizeof(aProID), &cbNeeded ); /* Total number of processes in the system */nProcess = cbNeeded /sizeof ( DWORD ); /* stats GDI for each process Number of objects */for ( INT i=0; i < nProcess; i ++ ) { HANDLE hPro = ::OpenProcess (PROCESS_QUERY_INFORMATION |    PROCESS_VM_READ, FALSE, aProID[i] ); nGDINums += ::GetGuiResources ( hPro, GR_GDIOBJECTS ); CloseHandle ( hPro ); } return nGDINums; } Use this check program to do the following tests: 1 Modify the Windows 2000 registry key" The GDIProcessHandleQuota value is 12000; 2 Open a check process and create 11,000 GDI objects in it! 3 Open the second check process (the first process does not close), creating 11000 GDI objects in it. The test results show that the object of the first process can be created smoothly, and the object of the second process cannot be created smoothly. This shows that in Windows 2000, the number of GDI objects that each process can create is not only inside the process. Certain limitations, but also limited by the entire operating system. After many experiments, when the total number of GDI objects in the Windows 2000 system reaches a value after 15900, the process can no longer create GDI objects, and the system becomes unstable. As for the critical value, The results of each test are not consistent, but they are all after 15900. The above test was done in Windows 2000, then, in Windows 2003, what is the situation? Immediately, to the 2003 system, modify the registry key "GDIProcessHandleQuota" to 20000, then run the test program and create 20,000 GDI objects in it, everything works! Change again, 30,000, running, still normal; ... until the 70,000, the system will run the interface drawing problem, in this case, have to make the assumption: Is it possible to cancel the customer GDI handle up to 16K in Windows 2003 The limit, and the limit is set to 64K? In order to verify this speculation, I use the check program to directly create 64K GDI resources. The results show that when the process creates a certain GDI object, it cannot create a new GDI object, which indicates that the above speculation is not completely correct, however, Based on the experimental experience in Windows 2000, it is quickly thought that the GDI objects that can be created by the system in Windows 2003 should be limited by the operating system, that is: Windows 2003 relaxes the GDI objects that each process can create. The number, but the number of GDI objects in the entire system cannot exceed a certain value. To verify this result, do the following test: 1 Modify the Windows 2003 registry key "GDIProcessHandleQuota" value is 50000; 2 Open a check process, create 40,000 GDI objects in it! 3 Open the second check process (the first process does not close), creating 40,000 GDI objects in it. The test results are basically similar to those in Windows 2000. The only difference is that in the process of creating a GDI object in the second process, the total GDI object in the system will not be created until it reaches a value after 63700. Again, this threshold is not fixed, but several trials have shown that when the total number of GDI objects reaches 63700, the system becomes unstable. Conclusion After the above analysis, we can know that in the Windows 2000/2003 operating system, the GDI object that each process can create is limited by three factors: the limitation of the two aspects of the system itself and the setting in the Windows registry. The maximum limit. First of all, the number of GDI objects that each process can create is 64K in theory, but in Windows 2000, the system can hardly set the number of GDI handles that a client can create to not exceed 16K, but in fact, when the number of GDI objects reaches 12K, The system is not normal; in Windows 2003, the system has relaxed the limit on the number of GDI objects, so that the number of GDI objects that each process can use is close to 64K. Second, the number of GDI objects that each process can create is also limited by the operation. The total number of GDI objects in the system; in Windows 2000, when the total GDI object in the system reaches a value after 15900, the process can no longer create a new GDI object; in 20003, this value is increased to some after 63700. Values. However, which value is not fixed. Finally, the maximum number of GDI objects that a process can create is also limited by the value set by the "GDIProcessHandleQuota " entry in the registry under HKEY_LOCAL_MACHINE\\ SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows, which sets each in Windows. The maximum number of GDI objects that a process can create. In Windows 2000 and 2003 systems, the default is 10000, which explains why the interface is confusing after the number of GDI objects created by the program reaches 9999.


Copyright © Windows knowledge All Rights Reserved