SYSTEM_INFO
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;
MIN : 65536因為前面64KB is always free
WOW64: 如果32 process在64 bit os跑, 用getsysteminfo會拉到錯的, 要用GetNativeSystemInfo來拉
MEMORSTATUS
typedef struct _MEMORYSTATUS {
DWORD dwLength;
DWORD dwMemoryLoad;
SIZE_T dwTotalPhys;
SIZE_T dwAvailPhys;
SIZE_T dwTotalPageFile;
SIZE_T dwAvailPageFile;
SIZE_T dwTotalVirtual;
SIZE_T dwAvailVirtual;
} MEMORYSTATUS, *LPMEMORYSTATUS;
length必須要先設
Load: use percent memory
Commit : commit是一個狀態, page被標記成commit後才能被load到實體記憶體上
如果超過4G, 要用Ex版
如何得到某個page上的資訊?
Virtual Query 傳baseAddress的pointer給他, 傳memory_basic_information的structure pointer
typedef struct _MEMORY_BASIC_INFORMATION { PVOID BaseAddress; PVOID AllocationBase; DWORD AllocationProtect; SIZE_T RegionSize; DWORD State; DWORD Protect; DWORD Type; } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
allocationBase: 是只用virtual alloc所分配出來的base addr base address: 是只要query這段的base addr
Stat: MEM_COMMIT MEM_FREE MEM_RESERVE
- Working set 算的是process所有的resource包含share memory, physical memory
- private bype是這個process真的能用的, 有包含page out的那些
Ch15 Using virtual memory in your own
How to reserving a region?
VirtualAlloc with starting addr, size, type
RESET: flag data in the range is no longer of interest reserve size must allocate 64kb
How to commit a region reserve first and commit. ex want to commit 6kb, reserver region start 2 kb (5242880 is the first address + 2*1024) + 6kb
large page support, GetLargePageMinimum() performance很好!
decommit : virtualFree dwsize = 0, 不得指定region大小讓系統自己處理 freetype= release會先 discommit > free 如果只想discommit, 就不要用release
virtual protect reset: 目的在於減少IO, reset也是整個page不可指定大小, size應為page size
AWE:address windows extension 會永遠在memory上不會到disk 是在額外的空間request, 不會再process address space被看到
AllocateUserPhisicalPage RamPage是由系統決定的, 不應該更改 RAM block are not share.