zoukankan      html  css  js  c++  java
  • HeapCreate深入研究

    本机:win7(x86),4G内存

    #include"stdafx.h"
    #include<windows.h>
    #include<stdio.h>
    #include<tchar.h>
    #include<iostream>

    using namespace std;
    HANDLE hHeap;
    int _tmain(int argc, _TCHAR* argv[]){
        SYSTEM_INFO systeminfo;
        GetSystemInfo(&systeminfo);
        cout<<"page"<<systeminfo.dwPageSize<<endl;

        hHeap=HeapCreate(HEAP_GENERATE_EXCEPTIONS,1024,4096);  //这里的最大堆空间需要注意一下


        if(NULL==hHeap){
            printf("HeapCreate失败 ");
            return 1;
        }
        
        for(int i=0;i<40;i++){
          LPVOID p4=HeapAlloc(hHeap,HEAP_ZERO_MEMORY,100);
          cout<<i<<endl;
        }
        
        system("pause");
        return 0;
    }

         我这里设置的最大堆空间是4096,但是分配的时候只分配了2000,第21个就分配不了了。如果我把4096改成4097,则可以完成分配,查了MSDN,也没有搞清楚是为什么,希望知道的大神告知一下,不胜感激!

  • 相关阅读:
    第52周二Restful
    第52周一
    第51周日
    第51周六
    第51周五
    第51周四
    第51周三
    第51周二
    第51周一
    第50周日
  • 原文地址:https://www.cnblogs.com/duyy/p/3665985.html
Copyright © 2011-2022 走看看