Mail Archives: djgpp/2000/09/27/21:59:12
Damian Yerrick <Bullcr_pd_yerrick AT hotmail DOT comremovebullcr_p> wrote:
> On Tue, 26 Sep 2000 16:35:23 +0200 (IST), Eli Zaretskii
> <eliz AT is DOT elta DOT co DOT il> wrote:
>>malloc only reserves the address space, but doesn't actually page
>>in the memory until you access it. (This is explained in section
>>15.2 of the DJGPP FAQ list.) So using malloc is indeed the right
>>way of achieving what you want, even on memory-starved machines.
> What's the right way of achieving this on a HD-space-starved machine?
On a machine that's starved both of HD-space and of RAM, there's
absolutely no way to run a program that wants to use, say 20 Megs of
RAM at the same time. It's as simple as that. Memory space can't be
generated from thin air, not even by DJGPP magic.
There's a reason that virtual memory is called 'virtual', see? It's
sometimes (usually) there, but sometimes it won't be. And if it isn't,
no-one's going to help you against that.
If an application really wants to run on machine that has no more
than, say 10 Megs of RAM + swap space free for DPMI applications, then
it's in the responsibility of the *programmer* to ensure that it never
uses more than 10 Megs, at any time. Given that there are so many DPMI
servers that either refuse or are not able to report reliable figures of
how much memory will be available, this leaves roughly two choices:
1) make it runtime-configurable by the user.
2) do all the memory management yourself, by never doing more than one
single, huge malloc(), at the beginning of the program. Hand out
portions of that by your own malloc() substitute function. The 'big'
malloc can start with what dpmi_report_free_memory_information(),
try to allocate all of it, and walk down from there until it
gets a successful malloc(). Or it can be a series of as many 'large'
succeeding calloc() calls as the system will grant, before it starts
reporting out of memory. You risk breaking libc functions that want
to use malloc() themselve, by this strategy, though.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -