BOOL EmptyWorkingSet(HANDLE hProcess);
引数の意味は以下の通り。
| hProcess | ワーキングセットのサイズを0にするプロセスのハンドル |
戻り値は、関数の実行に成功したか否かを表す真偽値である。
void TestWsEmpty()
{
HWND hWnd;
char WindowTitle[1000];
DWORD ProcessId;
HANDLE hProcess;
BOOL bResult;
PROCESS_MEMORY_COUNTERS MemInfo;
int i;
for(i=5; i>0; i--) {
printf("%d秒前\n", i);
Sleep(1000);
}
hWnd = GetForegroundWindow();
GetWindowText(hWnd, WindowTitle, 1000);
GetWindowThreadProcessId(hWnd, &ProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessId);
printf("target: %s\n", WindowTitle);
bResult = EmptyWorkingSet(hProcess);
if(!bResult) {
printf("working-set can not empty.\n");
return;
}
printf("wait 10 seconds...\n");
Sleep(10000);
GetProcessMemoryInfo(hProcess, &MemInfo, sizeof(MemInfo));
printf("current working-set size: %d\n", MemInfo.WorkingSetSize);
}