[OT] Free store and virtual address space

V

v4vijayakumar

When free store got exhausted, request for more memory issues an
error. Why this behavior is chosen instead of, creating new virtual
address space? What is the rationale behind this decision?
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

When free store got exhausted, request for more memory issues an
error. Why this behavior is chosen instead of, creating new virtual
address space? What is the rationale behind this decision?

This is not a C++ question since C++ can run on computers that does
not have virtual memory, and this is not specific to C++ so you should
probably have asked this in a newsgroup for your OS instead.

Because when the free store is exhausted it means that the virtual
address space is full, creating a new virtual address space would do
no good since a process can only access memory in it's own virtual
address space (that's the whole idea).

But lets play with the idea that you can access memory in some other
address space for a second, then given a pointer to an address, in
which address space should you then look for the data the pointer
points to?

It seems like you have not yet completely understood virtual memory,
so I'd advice you to either find a good OS-book or google a bit on the
subject.
 
S

Salt_Peter

When free store got exhausted, request for more memory issues an
error. Why this behavior is chosen instead of, creating new virtual
address space? What is the rationale behind this decision?

Why should C++, or any language, be managing a store provided by an
operating system or some other facility?

Consider as well that if you are in fact exhausting the free store,
perhaps deallocating resources appropriately is the solution, don't
you think? After all - that is your responsability.
 
F

faceman28208

When free store got exhausted, request for more memory issues an
error. Why this behavior is chosen instead of, creating new virtual
address space? What is the rationale behind this decision?

You have a system OS concept and a C++ concept mixed together.

First of all, let's assume that you are working on a virtual memory
system. Your memory allocator is probably calling the OS to allocate
large chunks of memory. When you call new, the request is handled by
subdividing these chunks. If no memory is available within an existing
"chunk", the allocator will call the OS for more memory.

On a VM system, these new "chunks" will probably come from increasing
the virtual address space of the process.

However, even in a VM system there are limits to how much memory is
available.

- There are architectural limitations. For example in a 32-bit system
you may be limited to a maximum of 1GB of memory in a process.

- There may be hardware limits. A particular CPU model may limit the
maximum process addressible memory.

- There may be OS limits. The OS may impose a maximum page table size
that limits the size of the processor's address space.

- There may be quota limits. The OS may permit the administrator to
limit a particular user to a maximum virtual memory side.

- There may be resource limits. The size of the paging file may be too
small to accomodate a memory allocation.

In short, even virtual memory has its limits.
 
V

v4vijayakumar

This is not a C++ question since C++ can run on computers that does
not have virtual memory, and this is not specific to C++ so you should
probably have asked this in a newsgroup for your OS instead.

....

Prefixed [OT] to the subject, but now I couldn't see it.

I accept it is our responsibility to free resources we use. There are
limits in every resources we use, but this does not justify the
decision. I think (?), creating new address space, when there is no
more memory is quite possible. My question is _why_ this is not the
behavior (of many, or, almost all, or, all languages)?
 
M

Markus Schoder

This is not a C++ question since C++ can run on computers that does not
have virtual memory, and this is not specific to C++ so you should
probably have asked this in a newsgroup for your OS instead.
...

Prefixed [OT] to the subject, but now I couldn't see it.

I accept it is our responsibility to free resources we use. There are
limits in every resources we use, but this does not justify the
decision. I think (?), creating new address space, when there is no more
memory is quite possible. My question is _why_ this is not the behavior
(of many, or, almost all, or, all languages)?

It is a feature of the OS not the language as others have already
explained. I am here on a Linux 64bit system -- if I switch on memory
overcommit allocations orders of magnitude larger than the available
virtual memory will not fail.

This is a dangerous thing to do however because if my program starts
using this memory (i.e. writing to it) eventually the virtual memory will
be exhausted causing processes to be killed based on heuristics.
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

You have a system OS concept and a C++ concept mixed together.

First of all, let's assume that you are working on a virtual memory
system. Your memory allocator is probably calling the OS to allocate
large chunks of memory. When you call new, the request is handled by
subdividing these chunks. If no memory is available within an existing
"chunk", the allocator will call the OS for more memory.

On a VM system, these new "chunks" will probably come from increasing
the virtual address space of the process.

However, even in a VM system there are limits to how much memory is
available.

- There are architectural limitations. For example in a 32-bit system
you may be limited to a maximum of 1GB of memory in a process.

4GB actually, but I think you knew that.
- There may be hardware limits. A particular CPU model may limit the
maximum process addressible memory.

- There may be OS limits. The OS may impose a maximum page table size
that limits the size of the processor's address space.

Most desktop/server OS use a bit of the virtual memory to map in the
kernel, which usually leaves only 3GB to the application on a 32bit
architecture (2 on Windows by default, can be increased to 3).
 
B

Bo Persson

v4vijayakumar wrote:
:: On 7 Maj, 10:53, v4vijayakumar <[email protected]>
:: wrote:
::
::: When free store got exhausted, request for more memory issues an
::: error. Why this behavior is chosen instead of, creating new virtual
::: address space? What is the rationale behind this decision?
::
:: This is not a C++ question since C++ can run on computers that does
:: not have virtual memory, and this is not specific to C++ so you
:: should probably have asked this in a newsgroup for your OS instead.
::
:
: ...
:
: Prefixed [OT] to the subject, but now I couldn't see it.
:
: I accept it is our responsibility to free resources we use. There are
: limits in every resources we use, but this does not justify the
: decision. I think (?), creating new address space, when there is no
: more memory is quite possible. My question is _why_ this is not the
: behavior (of many, or, almost all, or, all languages)?

We have a particular problem right now, that for 32-bit systems the amount
of physical memory is about the same as the virtual address space. That
makes virtual memory much less useful than it "used to" be.

You will also soon see that as a reason to move on to a 64 bit OS, where the
virtual address space is agai much large than physical memory.



Bo Persson
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top