new and VirtualAlloc

G

George2

Hello everyone,


I heard some points that the memory allocated by new does not belongs
to virtual memory, and onlymemory allocated by VirtualAlloc belongs to
virtual memory.

1.

I think this statement is not correct. Since all memory touched by
current process belongs to virtual memory (either reserved or
committed). No matter how (through which API) developer is using.

2.

And new always utilize VirtualAlloc in underlying internal
implementation code, so new (in implementation point of view) will
consume virtual memory -- the same as what VirtualAlloc does.

Are my points (1) and (2) correct?


thanks in advance,
George
 
J

jkherciueh

George2 said:
Hello everyone,


I heard some points that the memory allocated by new does not belongs
to virtual memory, and onlymemory allocated by VirtualAlloc belongs to
virtual memory.
[snip]

The C++ language does neither define virtual memory nor VirtualAlloc.

You should ask your question in a forum dealing with whatever environment
defines VirtualAlloc. Please have a look at the FAQ for a list of news
groups where topical answers to your question could provide more useful
information.


Best

Kai-Uwe Bux
 
J

James Kanze

George2 said:
I heard some points that the memory allocated by new does not
belongs to virtual memory, and only memory allocated by
VirtualAlloc belongs to virtual memory.

It depends on the implementation. There's no VirtualAlloc
function on my machines, and I've worked on machines with no
virtual memory. On all implementations on typical general
purpose machines today, however, I'm pretty sure that the memory
allocated by new is part of the virtual memory pool, although
the details depend on the implementation.

At least some implementions I've seen create an anonymous file
and mmap that to get memory from the system. Depending on the
OS and the tools used to measure, such an implementation may
appear to not use virtual memory. Also, some OS's don't
actually map the address until it first page faults, so pages
which haven't been accessed may appear to not use virtual
memory.
1.
I think this statement is not correct. Since all memory touched by
current process belongs to virtual memory (either reserved or
committed). No matter how (through which API) developer is using.
2.
And new always utilize VirtualAlloc in underlying internal
implementation code, so new (in implementation point of view) will
consume virtual memory -- the same as what VirtualAlloc does.
Are my points (1) and (2) correct?

I don't understand them. It's certainly possible to lock an
address range into real memory on most (all?) systems, provided
you have enough rights. On the other hand, it's probably
physically impossible to address memory without going through
the MMU (which manages virtual memory)---is this what you mean
by (1). And as for (2), the operator new functions on my
systems definitly don't go through VirtualAlloc, since there is
no such function---depending on the implementation, they either
user mmap or sbrk. (I think the implementation under Linux uses
mmap, and the one under Solaris uses sbrk, but I'm not sure. I
know, however that when I use the Boehm collector under Linux, I
use mmap, but of course, that's a different implementation than
the standard malloc/operator new of g++.)
 
J

Jerry Coffin

Hello everyone,


I heard some points that the memory allocated by new does not belongs
to virtual memory, and onlymemory allocated by VirtualAlloc belongs to
virtual memory.

[ questions elided ]
Are my points (1) and (2) correct?

It's all Windows specific (to put mildly) but yes. If you want to know
more about things like this, I'd advise asking someplace like
comp.os.ms-windows.programmer.win32.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top