Re: malloc's out-of-memory error handling

From: Casper H.S. Dik (Casper.Dik_at_Sun.COM)
Date: 07/02/04


Date: 02 Jul 2004 17:22:19 GMT

Pascal Bolzhauser <pascal@concept.de> writes:

>FreeBSD 3.4-RELEASE - 512 MB malloc: Cannot allocate memory
>SunOS 5.7 sparc - 1124 MB malloc: Resource temporarily unavailable
>AIX 1 5 - 128 MB malloc: Not enough space
>HP-UX B.11.00 9000/785- 1015 MB malloc: Not enough space
>Linux 2.2.17 i686 - 588 MB malloc: Cannot allocate memory

Standards compliant.

>Linux 2.4.19 x86_64 - 1958 MB Killed
>Linux 2.4.17 i686 - 1802 MB Killed
>Linux 2.4.17-mckinley-smp ia64 - 2015 MB Killed

Non compliant.

I think you need to disable "lazy swap allocation" or whatever they
call it (enable memory overcommit?)

>If my test program tries to access the memory address returned from
>malloc it receives a kill signal (which can't be handled).
>Any (simple) ideas how to realize that there is no more physical memory
>availabel, so my program can terminate with an out-of-memory error
>instead of being killed?

The C standard says that such behaviour is not allowed.

Casper

-- 
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.