首页 > Windows开发 > 详细

27 windows_27_windows_Virtual_Memory 虚拟内存

时间:2016-06-10 12:30:32      阅读:264      评论:0      收藏:0      [点我收藏+]

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. }





27 windows_27_windows_Virtual_Memory 虚拟内存

原文:http://www.cnblogs.com/nfking/p/5573498.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!