They are great learning resources and I have read them for 2 hours. I
"George" wrote:
I have read some documents in MSDN about VirtualAlloc API
and HeapAlloc API,
but I am still confused about what is the differences
between VirtualAlloc
and HeapAlloc? Seems they allocate memory from different
places?
I'd suggest you to follow Scott's advice: Don't use low
level OS calls unless you're absolutely required to.
`VirtualAlloc' allocates memory directly from OS. That's why
it has OS specific limitations like allocating in 4K chunks,
address alignment etc.
`HeapAlloc' calls `VirtualAlloc' internally. It returns you
aleady pre-allocated memory from process' heap. It is
somewhat similar to CRT's `malloc'.
If you want to understand the differences, then you should
read at least following articles:
"Managing Virtual Memory in Win32"
http://msdn2.microsoft.com/en-us/library/ms810627.aspx
"Managing Heap Memory in Win32"
http://msdn2.microsoft.com/en-us/library/ms810603.aspx
They are quite old, but mostly relevant even today. For
comprehensive material on Win32 memory management I'd
suggest to refer to good book:
"rogramming Applications for Microsoft Windows" by Jeffrey
Richter
http://www.microsoft.com/MSPress/books/2345.aspx
HTH
Alex