如何使用 GetProcessWorkingSetSize 获得某个当前进程的内存使用率?

sheerfish999 2006-01-09 01:14:25
声明如下:
Private Declare Function GetProcessWorkingSetSize Lib "kernel32" Alias "GetProcessWorkingSetSize" (ByVal hProcess As Long, lpMinimumWorkingSetSize As Long, lpMaximumWorkingSetSize As Long) As Long

hProcess是对应进程句柄

我搜了一下,但都没有什么合理的解决办法,到底如何使用这个API? 最好有代码举例
...全文
387 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sheerfish999 2006-01-09
  • 打赏
  • 举报
回复
狂谢!
rainstormmaster 2006-01-09
  • 打赏
  • 举报
回复
另外,我感觉你的问题使用GetProcessMemoryInfo这个api函数更合适一些,下面是GetProcessMemoryInfo的说明:
GetProcessMemoryInfo

The GetProcessMemoryInfo function retrieves information about the memory usage of the specified process.


BOOL GetProcessMemoryInfo(
HANDLE Process,
PPROCESS_MEMORY_COUNTERS ppsmemCounters,
DWORD cb
);

Parameters
Process
[in] Handle to the process. The handle must have the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights. For more information, see Process Security and Access Rights.
ppsmemCounters
[out] Pointer to the PROCESS_MEMORY_COUNTERS or PROCESS_MEMORY_COUNTERS_EX structure that receives information about the memory usage of the process.
cb
[in] Size of the ppsmemCounters structure, in bytes.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.



这个:
http://www.vbaccelerator.com/home/VB/Tips/Getting_Process_Information_Using_PSAPI/article.asp
是vb的例子,应该可以满足你的要求
rainstormmaster 2006-01-09
  • 打赏
  • 举报
回复
这个没什么好说的,你把进程句柄传进去, lpMinimumWorkingSetSize和lpMaximumWorkingSetSize As Long都是输出的参数:

dim lpMinimumWorkingSetSize as long
dim lpMaximumWorkingSetSize as long
hProcess=你自己想办法获取(一般就是用openprocess)

GetProcessWorkingSetSize hProcess,lpMinimumWorkingSetSize,lpMaximumWorkingSetSize
msgbox lpMinimumWorkingSetSize
msgbox lpMaximumWorkingSetSize

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧