27 windows_27_windows_Virtual_Memory 虚拟内存

windows_27_windows_Virtual_Memory 虚拟内存


  1. // windows_27_windows_Virtual_Memory.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include <windows.h>
  5. #include <conio.h>
  6. void Status( )
  7. {
  8. MEMORYSTATUS status = { 0 };
  9. status.dwLength = sizeof( status );
  10. GlobalMemoryStatus( &status );
  11. printf( "总共的物理内存:%u\n", status.dwTotalPhys);
  12. printf( "剩余的物理内存:%u\n", status.dwAvailPhys);
  13. printf( "总共的分页:%u\n", status.dwTotalPageFile);
  14. printf( "剩余的分布:%u\n", status.dwAvailPageFile);
  15. printf( "总共的虚拟:%u\n", status.dwTotalVirtual);
  16. printf( "剩余的虚拟:%u\n", status.dwAvailVirtual);
  17. printf( "内存使用率:%d\n",status.dwMemoryLoad );
  18. }
  19. void Virual( )
  20. {
  21. Status( );
  22. //地址分配 - 预订
  23. CHAR *pszBuf = (CHAR*)VirtualAlloc( NULL, 1024 * 1024 * 1024, MEM_RELEASE, PAGE_READWRITE );
  24. getchar( );
  25. Status( );
  26. //内存提交
  27. pszBuf = (CHAR*)VirtualAlloc( NULL, 1024 * 1024 * 1024, MEM_COMMIT, PAGE_READWRITE );
  28. Status( );
  29. if (pszBuf == NULL)
  30. {
  31. printf( "failed!\n" );
  32. }
  33. getchar( );
  34. //strcpy_s( pszBuf,10, "hello virtual\n" );
  35. printf( "%s", pszBuf );
  36. VirtualFree( pszBuf, 1024 * 1024 * 1024, MEM_RELEASE );
  37. }
  38. int _tmain(int argc, _TCHAR* argv[])
  39. {
  40. Virual( );
  41. Status( );
  42. return 0;
  43. }





posted @ 2016-06-10 12:01  -刀狂剑痴-  阅读(262)  评论(0编辑  收藏  举报