I have tested about HeapAlloc and HeapFree in Win32 c++.
I have created private heap with HeapCreate(0,0,0)
.
Next, I have alloced 100KB with HeapAlloc(_heaphandle, 0, 1024*100)
.
The process memory increased about 100KB with some overhead. I have checked this process memory with "process tab of windows work manager".
I have alloced 100KB some times. So, I have got following result.
process memory : 1,312KB committed:3472, uncommitted:25804开发者_Python百科8, alloced: 0
process memory : 1,420Kb committed:7544, uncommitted:151552, alloced: 102400
process memory : 1,524Kb committed:11616,uncommitted:45056, alloced: 204800
process memory : 1,632KB ............. alloced: 307200
process memory : 1,736KB ............. alloced: 409600
Next, I have freed memory with HeapFree(_heaphandle, 0, pointer)
.
But, the process memory doesn't return memory. I'm really curious when the process memory free.
I have got following result:
process memory : 1,736KB committed:23744, uncommitted:876544, alloced: 409600
process memory : 1,736Kb committed:126152,uncommitted:876544, alloced: 307200
process memory : 1,736Kb committed:228592,uncommitted:876544, alloced: 204800
Finally, I have destroyed private heap with HeapDestroy(heaphandle)
.
then, all heap memory free.
The Process memory goes to initial value 1,312KB.
If I use many memory, I am concerned to suffer from lack of memory.
You won't suffer from lack of memory. When you do HeapFree
the HeapManager may not actually release it back to the OS and might keep it for future allocations. So when the next time you do HeapAlloc
it can allocate from that memory.
精彩评论