zoukankan      html  css  js  c++  java
  • C++内存管理

    #include<Windows.h>
    #include<iostream>
    using namespace std;
    void main()
    {
    	MEMORYSTATUS ms;       //存储状态
    	LPVOID pVir;
    	LPVOID pMal;
    	GlobalMemoryStatus(&ms);
    	cout<<"分配存储前的存储状态"<<endl;
    	cout<<"存储状态长度"<<ms.dwLength<<"Bytes"<<endl;
    	cout<<"本地存储"<<ms.dwMemoryLoad<<"%"<<endl;
    	cout<<"全部物理存储"<<ms.dwTotalPhys/(1024*1024)<<"MB"<<endl;
    	cout<<"全部页文件"<<ms.dwTotalPageFile/(1024*1024)<<"MB"<<endl;
    	cout<<"可用页文件"<<ms.dwAvailPageFile/(1024*1024)<<"MB"<<endl;
    	cout<<"全部虚拟存储"<<ms.dwTotalVirtual/(1024*1024)<<"MB"<<endl;
    	cout<<"可用虚拟存储"<<ms.dwAvailVirtual/(1024*1024)<<"MB"<<endl;
    	cout<<"现在分配32M虚拟存储和16M物理存储"<<endl;
    	pVir=VirtualAlloc(NULL,1024*1024*32,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
    	if(!pVir)
    	{
    		cout<<"虚拟存储分配失败"<<endl;
    	}
    	pMal=malloc(1024*1024*16);
    	GlobalMemoryStatus(&ms);
    	cout<<"分配存储后的存储状态"<<endl;
    	cout<<"存储状态长度"<<ms.dwLength<<"Bytes"<<endl;
    	cout<<"本地存储"<<ms.dwMemoryLoad<<"%"<<endl;
    	cout<<"全部物理存储"<<ms.dwTotalPhys/(1024*1024)<<"MB"<<endl;
    	cout<<"全部页文件"<<ms.dwTotalPageFile/(1024*1024)<<"MB"<<endl;
    	cout<<"可用页文件"<<ms.dwAvailPageFile/(1024*1024)<<"MB"<<endl;
    	cout<<"全部虚拟存储"<<ms.dwTotalVirtual/(1024*1024)<<"MB"<<endl;
    	cout<<"可用虚拟存储"<<ms.dwAvailVirtual/(1024*1024)<<"MB"<<endl;
    	cout<<"现在释放32M虚拟存储和16M物理存储"<<endl;
    	if(!VirtualFree(pVir,0,MEM_RELEASE))
    	{
    		cout<<"释放虚拟存储失败"<<endl;
    	}
    	free(pMal);
    	GlobalMemoryStatus(&ms);
    	cout<<"释放存储后的存储状态"<<endl;
    	cout<<"存储状态长度"<<ms.dwLength<<"Bytes"<<endl;
    	cout<<"本地存储"<<ms.dwMemoryLoad<<"%"<<endl;
    	cout<<"全部物理存储"<<ms.dwTotalPhys/(1024*1024)<<"MB"<<endl;
    	cout<<"全部页文件"<<ms.dwTotalPageFile/(1024*1024)<<"MB"<<endl;
    	cout<<"可用页文件"<<ms.dwAvailPageFile/(1024*1024)<<"MB"<<endl;
    	cout<<"全部虚拟存储"<<ms.dwTotalVirtual/(1024*1024)<<"MB"<<endl;
    	cout<<"可用虚拟存储"<<ms.dwAvailVirtual/(1024*1024)<<"MB"<<endl;
    }

  • 相关阅读:
    php遍历目录
    PHP处理一个5G文件,使用内存512M的,数据为整形,从大到小排序,优化排序算法
    百钱买百鸡问题 php版本
    青蛙跳100级台阶算法,完整可运行,php版本
    网站如何整体换角度
    SOA架构设计(转发)
    一些稍微复杂点的sql语句
    php变量和数组大小限制
    uploadify中文开发文档,解决php多图上传
    mysql索引的一些知识
  • 原文地址:https://www.cnblogs.com/zztong/p/6695214.html
Copyright © 2011-2022 走看看