标签:
// windows_27_windows_Virtual_Memory.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <conio.h>
void Status( )
{
MEMORYSTATUS status = { 0 };
status.dwLength = sizeof( status );
GlobalMemoryStatus( &status );
printf( "总共的物理内存:%u\n", status.dwTotalPhys);
printf( "剩余的物理内存:%u\n", status.dwAvailPhys);
printf( "总共的分页:%u\n", status.dwTotalPageFile);
printf( "剩余的分布:%u\n", status.dwAvailPageFile);
printf( "总共的虚拟:%u\n", status.dwTotalVirtual);
printf( "剩余的虚拟:%u\n", status.dwAvailVirtual);
printf( "内存使用率:%d\n",status.dwMemoryLoad );
}
void Virual( )
{
Status( );
//地址分配 - 预订
CHAR *pszBuf = (CHAR*)VirtualAlloc( NULL, 1024 * 1024 * 1024, MEM_RELEASE, PAGE_READWRITE );
getchar( );
Status( );
//内存提交
pszBuf = (CHAR*)VirtualAlloc( NULL, 1024 * 1024 * 1024, MEM_COMMIT, PAGE_READWRITE );
Status( );
if (pszBuf == NULL)
{
printf( "failed!\n" );
}
getchar( );
//strcpy_s( pszBuf,10, "hello virtual\n" );
printf( "%s", pszBuf );
VirtualFree( pszBuf, 1024 * 1024 * 1024, MEM_RELEASE );
}
int _tmain(int argc, _TCHAR* argv[])
{
Virual( );
Status( );
return 0;
}
27 windows_27_windows_Virtual_Memory 虚拟内存
标签:
原文地址:http://www.cnblogs.com/nfking/p/5573498.html