EnumProcesses()与CreateToolhelp32Snapshot() [英] EnumProcesses() vs CreateToolhelp32Snapshot()

查看:1092
本文介绍了EnumProcesses()与CreateToolhelp32Snapshot()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有什么区别我想知道 - 主要性能明智的 - 这两个Win32 API函数之间的 EnumProcesses()的和的 CreateToolhelp32Snapshot()的枚举所有活动进程和加载模块。或者,如果一个比另一个最好使用和为什么

I was wondering if there are any differences - mostly performance wise - between the two Win32 API functions EnumProcesses() and CreateToolhelp32Snapshot() for enumerating all active processes and loaded modules. Or if one is better than the other to use and why.

推荐答案

我认为他们是pretty多在性能方面(和结果),因为它们都调用相同的底层NT API,虽然CreateToolhelp32Snapshot()一样可能有轻微的开销,因为它创造了一个部分对象,并将所有的信息,它而EnumProcesses()/ EnumProcessModules()可以直接与用户提供的缓冲区。所不同的是在现实世界中表现可能忽略,虽然

I think they are pretty much the same in terms of performance (and results) as they both call the same underlying NT API, though CreateToolhelp32Snapshot() may have a slight overhead as it creates a section object and copies all the information to it whereas EnumProcesses()/EnumProcessModules() works directly with user-supplied buffers. The difference is probably negligible in real world performance, though.

我微微preFER EnumProcesses(),因为它是(IMO)一个简单的API使用,但如果你需要它CreateToolhelp32Snapshot()返回的信息。唯一的缺点EnumProcesses()是你应该调用它在一个循环中,你可能没有分配足够大的缓冲区; CreateToolhelp32Snapshot()负责缓冲区的管理为您服务。在实践中我只分配堆栈足够大的一个缓冲区来容纳1024进程ID或模块处理;到目前为止,我还没有碰到过一个系统,无论这些限制甚至远程接近触及。当然,我们对MAX_PATH同样的事情没有这么早就说过,现在我们正在运行到与该问题...

I slightly prefer EnumProcesses() as it is (IMO) a simpler API to use, but CreateToolhelp32Snapshot() returns more information if you need it. The only downside to EnumProcesses() is that you are supposed to call it in a loop as you may not have allocated a large enough buffer; CreateToolhelp32Snapshot() takes care of the buffer management for you. In practice I just allocate a buffer on the stack large enough to hold 1024 process ids or module handles; so far I have not come across a system where either of these limits was even remotely close to being reached. Of course we said the same thing about MAX_PATH not so long ago and now we are running into problems with that...

这篇关于EnumProcesses()与CreateToolhelp32Snapshot()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆