Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Jul 2003 14:54:42 +0100
From:      Pete French <pfrench@firstcallgroup.co.uk>
To:        freebsd-stable@freebsd.org
Subject:   Re: malloc does not return null when out of memory
Message-ID:  <E19fgYM-0007SV-00@mailhost.firstcallgroup.co.uk>
In-Reply-To: <20030724134104.GA83799@vmunix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> It's not normal.  If malloc cannot allocate memory it should return a
> null pointer.  How would my application know there is no more memory?

But the point is that is *can* allocate the memory. Allocating it
is not the same as being able to use it. The behaviour you want is for the
system to not only allocate the memory, but to also ensure that the total
amount allocated by the system can never exceed the amount the system has
available.

> page says that malloc will return null when there is no more memory to
> be had by the process.  It shouldn't return a bogus pointer so I can

Its not bogus - the trouble is that you cant tell at the time malloc returns
whether the pointer will be useable or not. You only find that out when
you try and use it, and whether theres any space or not depends oon what
else may have munched up (or released) memory between you making the call
to malloc() and actually writing to the location returned.

-pcf.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E19fgYM-0007SV-00>