Datesfat Chicks <> wrote:
> The reason for releasing memory when "new" fails is that without doing
> that, the application couldn't even make it to a point where it could
> finish writing log files and let the user know they're copulated.
There could be at least two things that might throw a spanner
into the works when you try to "pre-allocate" memory. First,
on multi-tasking systems when you release the pre-allocated
memory you're not always guaranteed that you will get it back
when you then call 'new' - a different process may have been
run in between and just grabbed the memory you released (if
this can happen depends a lot on the system and how it hand-
les memory). And then there's something called "memory over-
commitment", i.e. even though malloc() returns succesfully
you still might have your process killed when you try to use
it. This feature was added on some systems because there are
a lot of programs that do pre-allocation of memory they never
use, so the system signals that memory is available but may
not actually give it to you when you need it and memory has
become exhausted. This can only be avoided by either getting
the administrator of the machine to switch off overcommitment
or by "using" the memory you got (by writing to it). Of cour
se, the details again will be rather system specific.
On the other hand, is a scenario where memory is that exhaus-
ed that you won't get enough even for simple clean-up tasks
really something you have to worry that much about? Normally
you will run out of memory when you need really lots of it
and then there will typically still be enough available for
the clean-up (as long as they don't also need huge amounts).
So, is that a problem you need to solve in a way that there
is not the slightest chance that it can ever occur? As I
read in one of Tanenbaum's books sometimes the best solu-
tion to a rare problem can be to stick your head in the
sand and pretend that it won't happen (see also "ostrich
algorithm"

Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://toerring.de