Weird behaviour of C++ destructors

前端 未结 8 1329
无人及你
无人及你 2020-12-17 03:29
#include 
#include 
using namespace std;

int main()
{
    vector< vector > dp(50000, vector(4, -1));
    c         


        
8条回答
  •  情书的邮戳
    2020-12-17 03:46

    It's definitely HeapFree that's slowing this down, you can get the same effect with the program below.

    Passing parameters like HEAP_NO_SERIALIZE to HeapFree doesn't help either.

    #include "stdafx.h"
    #include 
    #include 
    
    using namespace std;
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    HANDLE heap = HeapCreate(0, 0, 0);
    
    void** pointers = new void*[50000];
    
    int i = 0;
    for (i = 0; i < 50000; ++i)
    {
        pointers[i] = HeapAlloc(heap, 0, 4 * sizeof(int));
    }
    
    cout << i;
    for (i = 49999; i >= 0; --i)
    {
        HeapFree(heap, 0, pointers[i]);
    }
    
    cout << "!";
    
    delete [] pointers;
    
    HeapDestroy(heap);
    }
    

提交回复
热议问题