什么是 Windows“用户对象”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/868490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are Windows "USER objects"
提问by JonDrnek
I'm trying to track down an issue in our MFC code that looks like a resource limitation issue. Memory and CPU look fine. According to the processes tab on the Task manager our GDI objects look in line with other applications, but our USER objects appear to be a factor of 10 greater then other applications.
我试图在我们的 MFC 代码中追踪一个看起来像资源限制问题的问题。内存和 CPU 看起来不错。根据任务管理器上的进程选项卡,我们的 GDI 对象看起来与其他应用程序一致,但我们的 USER 对象似乎比其他应用程序大 10 倍。
What is a "USER object" and what are the limits?
什么是“用户对象”,限制是什么?
采纳答案by Aardvark
Here is a "classic" MSDN article: Give Me a Handle, and I'll Show You an Object
这是一篇“经典”的 MSDN 文章:给我一个句柄,我会向你展示一个对象
Last time I was tracking down Windows object leaks (which i suspect you have) Process Explorerwas handy (handley?). The lower-pane could show some allocated system objects, plus it could do the simple USER, GDI, etc object counting.
上次我追踪 Windows 对象泄漏(我怀疑你有)时,Process Explorer很方便(handley?)。下部窗格可以显示一些已分配的系统对象,此外还可以进行简单的 USER、GDI 等对象计数。
The desktop heap, which is a pool of memory where the real "stuff" the handle represents lives (at least some handles, not kernel handles at least). It's sometimes not so much how many handles you have allocated but how much memory each objectunder that handle is using. You can debug the heap this way. It is a painto install.
在桌面堆,这是一个内存池,在那里真正的“东西”把手代表生命(至少一些把手,而不是内核处理至少)。有时与其说分配了多少句柄,不如说是该句柄下的每个对象使用了多少内存。您可以通过这种方式调试堆。安装起来很痛苦。
回答by Otávio Décio
Read all about it here:
在这里阅读所有相关信息:
Object Categories
The system provides three categories of objects: user, graphics device interface (GDI), and kernel. The system uses user objects to support window management, GDI objects to support graphics, and kernel objects to support memory management, process execution, and interprocess communications (IPC). For information about creating and using a specific object, refer to the associated overview.
对象类别
系统提供三类对象:用户、图形设备接口(GDI)和内核。系统使用用户对象来支持窗口管理,使用 GDI 对象来支持图形,以及使用内核对象来支持内存管理、进程执行和进程间通信 (IPC)。有关创建和使用特定对象的信息,请参阅相关概述。
and here:
和这里:
User Objects
User interface objects support only one handle per object. Processes cannot inherit or duplicate handles to user objects. Processes in one session cannot reference a user handle in another session.
There is a theoretical limit of 65,536 user handles per session. However, the maximum number of user handles that can be opened per session is usually lower, since it is affected by available memory. There is also a default per-process limit of user handles. To change this limit, set the following registry value:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERProcessHandleQuota
This value can be set to a number between 200 and 18,000.
用户对象
用户界面对象每个对象仅支持一个句柄。进程不能继承或复制用户对象的句柄。一个会话中的进程不能引用另一个会话中的用户句柄。
每个会话的理论限制为 65,536 个用户句柄。但是,每个会话可以打开的最大用户句柄数通常较低,因为它受可用内存的影响。还有一个默认的每个进程的用户句柄限制。要更改此限制,请设置以下注册表值:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERProcessHandleQuota
此值可以设置为 200 到 18,000 之间的数字。
回答by Tobi
I don't know whatthey are, but I do know they includewindow handles.
我不知道它们是什么,但我知道它们包括窗口句柄。
For window handles there is a system wide maximum of about 32000, and a per process maximum of 10000. (This may just be USER object limit, instead of just window handles.)
对于窗口句柄,系统范围的最大值约为 32000,每个进程的最大值为 10000。(这可能只是 USER 对象限制,而不仅仅是窗口句柄。)
The number of window handles may be very high if some way you are leaking window handles, or if you use huge amounts of windows. (Note that even simple controls like a text label consumes a single window handle.)
如果您以某种方式泄漏窗口句柄,或者如果您使用大量窗口,则窗口句柄的数量可能会非常高。(请注意,即使像文本标签这样的简单控件也使用单个窗口句柄。)
回答by Thomas Weller
Mark Russinovich is an expert on the subject. He has written the book "Windows Internals". Luckily, there's not only the book but also an article dating 2019-06-27.
Mark Russinovich 是这方面的专家。他撰写了《Windows 内部原理》一书。幸运的是,不仅有这本书,还有一篇日期为 2019-06-27的文章。
First he describes USER objects:
首先他描述了 USER 对象:
USER objects get their name from the fact that they represent user interface elements like desktops, windows, menus, cursors, icons, and accelerator tables (menu keyboard shortcuts).
USER 对象之所以得名,是因为它们代表用户界面元素,如桌面、窗口、菜单、光标、图标和加速器表(菜单键盘快捷键)。
And then continues describing the limits:
然后继续描述限制:
A basic limitation imposed by the window manager is that no process can create more than 10,000 USER objects.
窗口管理器强加的一个基本限制是没有进程可以创建超过 10,000 个 USER 对象。
and
和
One fundamental limitation on the number of USER objects comes from the fact that their identifiers were 16-bit values in the first versions of Windows, which were 16-bit. When 32-bit support was added in later versions, USER identifiers had to remain restricted to 16-bit values so that 16-bit processes could interact with windows and other USER objects created by 32-bit processes. Thus, 65,535 (2^16) is the limit on the total number of USER objects that can be created on a session
USER 对象数量的一个基本限制来自这样一个事实,即它们的标识符在 Windows 的第一个版本中是 16 位值,即 16 位。当在更高版本中添加 32 位支持时,用户标识符必须保持限制为 16 位值,以便 16 位进程可以与窗口和 32 位进程创建的其他 USER 对象交互。因此,65,535 (2^16) 是可以在会话上创建的 USER 对象总数的限制
He also explains the number mentioned by @Tobi:
他还解释了@Tobi 提到的数字:
for historical reasons, windows must have even-numbered identifiers, so there can be a maximum of 32,768 windows per session
由于历史原因,窗口必须具有偶数标识符,因此每个会话最多可以有 32,768 个窗口