공부/API
HeapAlloc & HeapFree & GetProcessHeap & HeapReAlloc & HeapSize
잠수함토끼
2008. 9. 7. 10:22
#undef UNICODE #include#include void HeapAllocation() { PINT32 p; //HeapAlloc: Default 영역이나 개인이 만든 Heap에 메모리를 할당하고자 할때 사용 //GetProcessHeap: Retrieve a heandle to the heap of the calling process p=(PINT32)HeapAlloc(GetProcessHeap(), 0, sizeof(int)*10); printf("first Pointer: %x\n",p); //HeapSize: Retrieve the size of a memory block allocated from heap printf("HeapSize: %d\n",HeapSize(GetProcessHeap(),0,p)); for(int i=0; i<10;i++) { printf("%d ",p[i]=i*2); } p=(PINT32)HeapReAlloc(GetProcessHeap(),0,p,100); printf("\n\nsecond Pointer: %x\n",p); printf("HeapSize: %d\n",HeapSize(GetProcessHeap(),0,p)); //HeapFree: Frees a memory block allocated from a heap HeapFree(GetProcessHeap(),0,p); } int main(void) { HeapAllocation(); return 0; }