Windows 信号量对象的大小是多少?
如何在 Windows 中查找信号量对象的大小?
我尝试使用 sizeof()
但我们无法将信号量对象的名称作为 sizeof 的参数。应该是手柄吧sizeof(HANDLE)
为我们提供了句柄的大小,而不是信号量的大小。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是所谓的“不透明手柄”。没有办法知道它到底有多大、包含什么或者任何函数内部如何工作。这使得 Microsoft 能够在每个新版本的 Windows 中完全重写实现(如果他们愿意),而不必担心破坏现有代码。这与类的公共和私有接口的概念类似。由于我们不在 Windows 内核上工作,因此我们只能看到公共接口。
更新:
通过创建一堆并监视 进程资源管理器。然而,由于它们很可能存在于内核中而不是用户空间中,因此它可能根本不会显示出来。无论如何,我们不保证任何其他版本的 Windows(过去或未来),包括补丁/服务包。
This what is known as an "opaque handle.". There is no way to know how big it really is, what it contains or how any of the functions work internally. This gives Microsoft the ability to completely rewrite the implementation with each new version of Windows if they want to without worrying about breaking existing code. It's a similar concept to having a public and private interface to a class. Since we are not working on the Windows kernel, we only get to see the public interface.
Update:
It might be possible to get a rough idea of how big they are by creating a bunch and monitoring what happens to your memory usage in Process Explorer. However, since there is a good chance that they live in the kernel and not in user space, it might not show up at all. In any case, there are no guarantees about any other version of Windows, past or future, including patches/service packs.
这是对你“隐藏”的东西。你不能说它有多大。它是一个内核对象,因此它可能根本不存在于您的地址空间中。这就像问“进程表有多大?”或“Windows 浪费了多少 MB?”。
我要补充一点,我在 Windows 7 32 位机器上做了一个小测试:100000 个内核信号量(名称为
X{number}
,其中 0 <= number < 100000)):4 mb内核内存和 8 mb 用户空间(均使用任务管理器测量)。内核空间中大约为 40 字节/信号量,用户空间中大约为 80 字节/信号量! (这在 Win32 中......在 64 位中它可能会加倍)It's something "hidden" from you. You can't say how big it is. And it's a kernel object, so it probably doesn't even live in your address space. It's like asking "how big is the Process Table?", or "how many MB is Windows wasting?".
I'll add that I have made a small test on my Windows 7 32 bits machine: 100000 kernel semaphores (with name
X{number}
with 0 <= number < 100000)) : 4 mb of kernel memory and 8 mb of user space (both measured with Task Manager). It's about 40 bytes/semaphore in kernel space and 80 bytes/semaphore in user space! (this in Win32... In 64 bits it'll probably double)