0

I am reading windows memory management. In that I read about VirtualAlloc() and heap functions. I understood both the concepts. But when I started to compare them, then I got confused.

I searched online about these concepts, I found lot of answers. But after reading them I still got confused. So to clarify my doubt I am asking few questions. You may feel these questions are duplicate.

1) When we call VirtualAlloc(), from where we get memory form? OR If we get memory from HeapAlloc(), is called as heap memory, If we get memory form VirtualAlloc(), is called as?

2) If memory we get from VirtualAlloc() and HeapAlloc() are from Virtual Address or if there is no difference b/n the memory then why do we need them.

3) I read that, if we want to allocate big chunk of memory(100MB) then we need to call VirtualAlloc(). What happens if I use HeapAlloc() to allocate big chunk of memory(100 MB). If it works fine then why do we need virtualAlloc().

4) I read that malloc() and new operator internally call HeapAlloc() for samller object and VirtualAlloc() for larger object. My question : In Windows to allocate memory form user mode do we have only these 2 API (virtualAlloc and HeapAlloc()).

5) In visual studio setting -> Linker -> system -> Heap Reserve size is 1MB. Is this is same same as default heap of the process.

Please help me to understand these concepts. If you know any good link or good book about this concept.

Umesha MS
  • 2,861
  • 8
  • 41
  • 60
  • [VirtualAlloc](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366887.aspx) is the low-level memory allocation function. It allocates memory in multiples of page sizes. The [Heap Functions](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366711.aspx) use `VirtualAlloc` to allocate memory, but add additional management on top of it, so that applications can request smaller chunks. Both APIs return pointers into the same virtual address space. Also see [Comparing Memory Allocation Methods](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366533.aspx). – IInspectable Feb 19 '16 at 11:37
  • It is not true that you need to call VirtualAlloc for big chunks of memory. In some cases it may give you better performance, or be more suitable for other reasons (alignment, for example) but you don't *need* it. – Harry Johnston Feb 19 '16 at 23:59

0 Answers0