提问:如何象NT任务管理器那样得到进程占用内存的大小?在WINCE下又该如何做?回答任何问题都可以,来者有分。

alfwolf 2003-09-19 12:44:59
如何象NT任务管理器那样得到进程占用内存的大小?在WINCE下又该如何做?]
不会是仅仅用GetProcessMemoryInfo吧?如果是,在WINCE下是不支持该函数的,那么是否有类似功能的api函数呢?
...全文
109 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
alfwolf 2003-09-19
  • 打赏
  • 举报
回复
谢谢大家,其实我主要是想在WINCE上使用,不过还是要谢谢大家
分数我会考虑再开帖加分,欢迎继续讨论。
kingzai 2003-09-19
  • 打赏
  • 举报
回复
http://www.codeguru.com/system/perfmon.shtml
mixtrue 2003-09-19
  • 打赏
  • 举报
回复
下面是PROCESS_MEMORY_COUNTERS结构的详细解释,搂住可以看看,
The PROCESS_MEMORY_COUNTERS structure contains the memory statistics for a process.

typedef struct _PROCESS_MEMORY_COUNTERS {
DWORD cb;
DWORD PageFaultCount;
DWORD PeakWorkingSetSize;
DWORD WorkingSetSize;
DWORD QuotaPeakPagedPoolUsage;
DWORD QuotaPagedPoolUsage;
DWORD QuotaPeakNonPagedPoolUsage;
DWORD QuotaNonPagedPoolUsage;
DWORD PagefileUsage;
DWORD PeakPagefileUsage;
} PROCESS_MEMORY_COUNTERS;
typedef PROCESS_MEMORY_COUNTERS *PPROCESS_MEMORY_COUNTERS;

Members
cb
The size of the structure, in bytes.
PageFaultCount
The number of page faults.
PeakWorkingSetSize
The peak working set size.
WorkingSetSize
The current working set size.
QuotaPeakPagedPoolUsage
The peak paged pool usage.
QuotaPagedPoolUsage
The current paged pool usage.
QuotaPeakNonPagedPoolUsage
The peak nonpaged pool usage.
QuotaNonPagedPoolUsage
The current nonpaged pool usage.
PagefileUsage
The current pagefile usage.
PeakPagefileUsage
The peak pagefile usage.

还有 GetProcessMemoryInfor 函数的详细解释哦!^_^

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

BOOL GetProcessMemoryInfo(
HANDLE Process, // handle to the process
PPROCESS_MEMORY_COUNTERS ppsmemCounters,
// structure that receives information
DWORD cb // size of the structure
);

Parameters
Process
Handle to the process.
ppsmemCounters
Pointer to the PROCESS_MEMORY_COUNTERS structure that receives information about the memory usage of the process.
cb
Specifies the size, in bytes, of the PROCESS_MEMORY_COUNTERS structure.
Return Value
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.

vcforever 2003-09-19
  • 打赏
  • 举报
回复
楼上的已经把所有的进程都枚举出来了!
然后再根据枚举出来的每一个进程调用GetProcessMemoryInfo()函数,就
可以取得每一个进程所占用的内存的大小,然后再把得到的数据加到一个列表框
中应该就可以了!
希望对你有所帮助!
祝你成功!
xiaohedou 2003-09-19
  • 打赏
  • 举报
回复
vckbase里有篇文章,“剖析Windows任务管理器开发原理与实现 Author: TOo2y[原创]”可惜讲的不全,估计作者是让大家看他的主页。


wuxfBrave 2003-09-19
  • 打赏
  • 举报
回复
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
CSystemanalyzer::PrintError(_T("CreateToolhelp32Snapshot for Process Error: %d\n"), GetLastError());
return FALSE;
}

ResetLiveTag(listProcess);

PROCESSENTRY32 ProcessEntry32;
ProcessEntry32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &ProcessEntry32))
{
do
{
CProcess *pProcess = GetProcess(listProcess, ProcessEntry32.th32ProcessID);
if (pProcess == NULL)
{
pProcess = new CProcess;
listProcess.AddTail(pProcess);
pProcess->SetLiveFlag(-1);
}
else
pProcess->SetLiveFlag(1);

pProcess->SetProcessEntry(ProcessEntry32);
if (ProcessEntry32.th32ProcessID == 0)
continue;

HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, ProcessEntry32.th32ProcessID);
if (hProcess == NULL)
{
CSystemanalyzer::PrintError(_T("打开进程(%d)失败!"), ProcessEntry32.th32ProcessID);
continue;
}

if (!GetProcessTimes(hProcess, &CreateTime ,&ExitTime ,&KernelTime, &UserTime))
CSystemanalyzer::PrintError(_T("GetProcessTimes Error: %d\r\n"), GetLastError());
else
pProcess->SetTime(CreateTime, ExitTime, KernelTime, UserTime);

PROCESS_MEMORY_COUNTERS PMCounter;
PMCounter.cb = sizeof(PROCESS_MEMORY_COUNTERS);
if (!GetProcessMemoryInfo(hProcess, &PMCounter, sizeof(PMCounter)))
CSystemanalyzer::PrintError(_T("GetProcessMemoryInfo Error: %d\n"), GetLastError());
pProcess->SetMemCounters(PMCounter);

DWORD dwPriority = GetPriorityClass(hProcess);
if (dwPriority == 0)
CSystemanalyzer::PrintError(_T("GetPriorityClass Error: %d\n"), GetLastError());

pProcess->SetPriority(dwPriority);
}
while (Process32Next(hProcessSnap, &ProcessEntry32));
}
else
CSystemanalyzer::PrintError(_T("ProcessEntry32First Error: %d\n"), GetLastError());

CloseHandle(hProcessSnap);
以上的代码枚举进程并得到进程的信息,,注意首先当前用户要有调试权限

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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