ci********@gmail.com wrote:
Hi friends,
Sorry for such basic question. but I wanted to know where does new
operator or malloc operator allocate memory? in actualy physical Main
memory or virtual memory?
When you call new or malloc, the memory is allocated from a free-memory
pool called 'Heap'. But this does not force you to use this. You can as
well have your implementation of new/malloc which would allocate
memory from some other place, say your own array kept seperate for
memory allocation. How feasible it is, my answer is that's why there's
new/malloc.
Virtual Memory as the name itself says is virtual. For a given address
in the virtual memory you cannot go any physical memory and say this it
it.
The underlying operating sytem provides a mapping from this virutal
memory to the pysical memory. Since a virtual memory is huge as
compared to the physical memory the operting system does something
called paging, where it takes some disk space and dumps the pages of
the process which is not currently executing if the executing process
needs more physical memory space. The virtual memory helps the
operating system do this without worrying about the process getting
screwed up because the address have changed. When a process is paged in
it might as well be located at a different physical memory than where
it was before being paged out. The mapping maintained by the underlying
operating system gaurantees that when the process access some variable
it will take the right value/variable whether or not it is always in
the same physical memory.
HTH
--
Taran