Connecting Tech Pros Worldwide Help | Site Map

memory allocation using new operator

  #1  
Old January 4th, 2007, 03:05 PM
cikkamikka@gmail.com
Guest
 
Posts: n/a
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?

  #2  
Old January 4th, 2007, 03:15 PM
Victor Bazarov
Guest
 
Posts: n/a

re: memory allocation using new operator


cikkamikka@gmail.com wrote:
Quote:
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?
'malloc' is not an operator. It's a function.

Both 'new' and 'malloc' allocate memory in "free store". What it is
depends on your operating system, your compiler (library), and your
code. You can have your own implementation of 'new' for any class
you define, which can get its memory anywhere you want.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  #3  
Old January 4th, 2007, 03:35 PM
cikkamikka@gmail.com
Guest
 
Posts: n/a

re: memory allocation using new operator



Victor Bazarov wrote:
Quote:
cikkamikka@gmail.com wrote:
Quote:
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?
>
'malloc' is not an operator. It's a function.
>
Both 'new' and 'malloc' allocate memory in "free store". What it is
depends on your operating system, your compiler (library), and your
code. You can have your own implementation of 'new' for any class
you define, which can get its memory anywhere you want.
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Correct. There are two things
1) I get virtual address space
2) I get virtual memory : here I guess when my Main memory exceeds then
OS gives me more memory from disk which is used as a page file.

So I meant to know that when I request for the memory from where the OS
gives me memory by reserving the space from actual Main memory or from
page file?

  #4  
Old January 4th, 2007, 03:45 PM
Victor Bazarov
Guest
 
Posts: n/a

re: memory allocation using new operator


cikkamikka@gmail.com wrote:
Quote:
[..] There are two things
1) I get virtual address space
Right. Always. It may or may not be the same as physical space.
Quote:
2) I get virtual memory : here I guess when my Main memory exceeds
then OS gives me more memory from disk which is used as a page file.
What's the difference between 1 and 2?
Quote:
So I meant to know that when I request for the memory from where the
OS gives me memory by reserving the space from actual Main memory or
from page file?
Hold on... You meant to know where the OS gives you memory? How
should we know? It's a perfect question for the newsgroup dedicated
to your OS, don't you think?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  #5  
Old January 4th, 2007, 08:15 PM
gpriv@axonx.com
Guest
 
Posts: n/a

re: memory allocation using new operator


Assuming that you using VM platform, on application level you never
deal with physical memory, it will allways be VM. If you are curious
where your data will physically reside, it is hard to tell it can be at
different places at different times (and sometimes even at the same
time):

CPU Register
Internal cash,
L2 cash,
DRAM,
page file

Hope it helps

cikkamikka@gmail.com wrote:
Quote:
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?
  #6  
Old January 5th, 2007, 06:55 AM
Taran
Guest
 
Posts: n/a

re: memory allocation using new operator


cikkamikka@gmail.com wrote:
Quote:
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

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem understanding returning a pointer and memory allocation krishna81m answers 1 October 4th, 2007 11:49 AM
dynamic memory allocation using new svbala answers 3 March 31st, 2007 07:53 AM
How do you define 2D arrays using New Operator? Dennis@NoSpam.com answers 34 July 23rd, 2005 12:05 AM
Memory allocation with new Avinash answers 10 July 22nd, 2005 06:28 AM