Re: Heap memory available (W32 console app in Visual C++)
CriCri <bitwyse@leTIRETmaquis.net> wrote:
The mechanism still isn't clear to me.
Read about virtual memory, e.g. here:
http://en.wikipedia.org/wiki/Virtual_memory
but amongst the user
processes does it just become 'first come first served' (like I said
before)?
Yes. Except that when you said that, you expected a sequence like this
to work:
if (wanted <= _memavl()) p = malloc(wanted);
Assuming _memavl existed (which it doesn't), you would be waiting in the
conceptual "first come first served" queue for your _memavl call, and
then back to the end of the queue for malloc call.
No, but that it would reserve a reasonable minimum (or refuse to start
it) and a maximum (of which not all might be always available).
It does: it "reserves" enough memory to fit your code, global variables
and some amount of stack for the primary thread. If there's not enough
memory even for that, the process would naturally fail to start.
I'm not sure what it means to "reserve" something that "might not be
always available". This sounds like an oxymoron to me. "Reserve X"
usually means "set X aside, so it's guaranteed to be available".
The
latter was exactly the point of my original question about _memavl():
how much can I possibly expect to get right now?
The problem is, of course, that between the time you receive the answer
(assuming you could, which you can't) and the time you can act on it,
the answer might already have become obsolete. Which makes the question
itself rather pointless.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925