[Bf-committers] Some words about a strange thing named
jlp at nerim.net
Fri Nov 25 12:21:21 CET 2005
Le 25 nov. 05 à 11:47, Jorrit Tyberghein a écrit :
> On 11/25/05, Jean-Luc Peurière <jlp at nerim.net> wrote:
>> hmm. on all current systems, when malloc fails, it means you have
>> run out of
>> *BOTH* physical and swap memory.
> This is NOT true. I can do a malloc(1000000000) (1000 megs) which will
> fail on a system that has NOT run out of any kind of memory. Having
> malloc fail does not mean the system is out of memory. It just means
> that there is not sufficient memory to handle the allocation request.
> If the allocation request is large the system may still be able to
> handle smaller allocation requests.
And that's a degenerate case. Before dealing with such cases better
that the most common ones work.
When malloc cannot grant an available physical block, it will try to
swap out enough
to do so.
So my point (and Ton or Alexander) stand. if malloc fail, you are in
a state where it is
unlikely you can recover or you just made an insanely big request.
Latter case can (and should) be protected by the coder, but in the
normal case, when this
fail, it is already too late.
I come from the old MacOs programming, where such problems were
common and a
nightmare to deal with as you had 2 heaps (your app and system) to
manage, but also
watch it was not fragmented.
Memory management with malloc is really imho a non-issue, if in the
rare cases where
the request can be insanely big, you are prepared to deal with null
More information about the Bf-committers