Thinking Different






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Tlhelp32.h>
#include <Psapi.h>
 
#pragma comment(lib, "Kernel32.lib")
#pragma comment(lib, "psapi.lib")
 
 
// SetProcessWorkingSetSize()를 이용한 메모리 최적화 소스
 
    HANDLE hProcess = NULL;
    int i=0;
 
    for( i=0; i<0xffff; i+=4 )
    {
        hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_SET_QUOTA, FALSE, i);
        
        if(hProcess)
        {
            SetProcessWorkingSetSize( hProcess, -1, -1 );
            CloseHandle(hProcess);
        }
 
        hProcess = NULL;
    }
 
 
 
 
// EmptyWorkingSet()를 이용한 메모리 최적화 소스
 
    HANDLE    hProcess = NULL;
    HANDLE    hSnap = INVALID_HANDLE_VALUE;
 
    PROCESSENTRY32 pe;
 
    hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(hSnap == INVALID_HANDLE_VALUE)
    {
        return -1;
    }
 
    pe.dwSize = sizeof(PROCESSENTRY32);
    if(Process32First(hSnap, &pe) == FALSE)
    {
        CloseHandle(hSnap);
        return -1;
    }
 
    do
    {
        hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
        if(hProcess)
        {
            EmptyWorkingSet(hProcess);
            CloseHandle(hProcess);
        }
 
        hProcess = NULL;
    } 
    while(Process32Next(hSnap, &pe));
 
    CloseHandle(hSnap);


아주 간단하게 메모리 최적화에 사용되는 소스를 작성해 보았다.