#include #include #define PAGE 4096 void *virtualAlloc (long size) { return VirtualAlloc (0, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); } BOOL virtualFree (void *a) { return VirtualFree (a, 0, MEM_RELEASE); } void main () { MEMORYSTATUS stat; GlobalMemoryStatus (&stat); printf ( "Global Memory Status:\r\n" "Total Physical: %d bytes\tAvailable Physical: %d bytes\r\n" "Total PageFile: %d bytes\tAvailable PageFile: %d bytes\r\n" "Total Virtual : %d bytes\tAvailable Virtual : %d bytes\r\n", stat.dwTotalPhys, stat.dwAvailPhys, stat.dwTotalPageFile, stat.dwAvailPageFile, stat.dwTotalVirtual, stat.dwAvailVirtual ); for (long nPages = 16000; nPages <= 520000; nPages += 10000) { long allocSize = nPages * PAGE; void *addr = virtualAlloc (allocSize); if (! addr) { printf ("Failed to allocate %d pages [%d bytes]\r\n", nPages, allocSize); break; } printf ("Allocated: %d pages [%d bytes] at 0x%08x\r\n", nPages, allocSize, addr); virtualFree (addr); } }