Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > memory allocation using new operator

Reply
Thread Tools

memory allocation using new operator

 
 
cikkamikka@gmail.com
Guest
Posts: n/a
 
      01-04-2007
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?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-04-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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


 
Reply With Quote
 
 
 
 
cikkamikka@gmail.com
Guest
Posts: n/a
 
      01-04-2007

Victor Bazarov wrote:
> (E-Mail Removed) wrote:
> > 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?

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-04-2007
(E-Mail Removed) wrote:
> [..] There are two things
> 1) I get virtual address space


Right. Always. It may or may not be the same as physical 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.


What's the difference between 1 and 2?

> 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


 
Reply With Quote
 
gpriv@axonx.com
Guest
Posts: n/a
 
      01-04-2007
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

(E-Mail Removed) 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?


 
Reply With Quote
 
Taran
Guest
Posts: n/a
 
      01-05-2007
(E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
how to use operator overloading with heap memory allocation. toton C++ 3 05-08-2006 05:40 AM
Allocation with new operator and Destroying with free operator saikishore.vanga@wipro.com C++ 8 12-22-2005 01:35 PM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM
new operator and memory allocation Lionel C++ 5 04-06-2005 03:51 PM



Advertisments