Dynamical heap allocation

>> Friday, January 22, 2010


#include <windows.h>
#include <iostream.h>

int main()
{
 HANDLE hHeap; // handle to the heap
 int *a = NULL; // pointer to array
 int h_size = 4096; // size of the heap
 int a_size = 2048; // size of array
 
 hHeap = HeapCreate(HEAP_NO_SERIALIZE, h_size, h_size); // create heap dynamically
 a = (int*)HeapAlloc(hHeap, NULL, a_size); // heap allocation
 cout << "a[10] = " << a[10] << endl;
 HeapFree(hHeap, NULL, a); // free memory from heap
 HeapDestroy(hHeap); // destroy the heap
 return 0;
}


HEAP_NO_SERIALIZE - allow parallel access to the heap.

0 comments: