[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] out of memory
From:       Mark Bucciarelli <mark () easymailings ! com>
Date:       2005-05-26 13:32:26
Message-ID: 4295CFEA.3020400 () easymailings ! com
[Download RAW message or body]

In C, I'm used to checking that malloc returns a non-null pointer to 
make sure you app is not out of memory.

How do you do this in C++?

What happens if the exceptions are disabled (like in kdelibs) and new 
can't allocate enough memory?

<quote>
Very few C++ application programmers, including myself, have any idea 
what happens when operator new throws in their app, because we don't 
write custom new operators that purposely fail during testing. Although, 
I do know what happens in my proxy server. It never starts.

But the issue is way more complicated, as both Linux and FreeBSD 
overcommit memory by default. What that means is malloc will not fail 
even if there is not enough physical memory available to meet the 
request. Memory pages aren't physically committed until they are written 
to. If applications start committing more pages then are available to 
the OS, the OS starts killing off processes. There is no chance to catch 
an exception from new, because more then likely your application is 
already dead before this happens. It blows a lot of developers minds 
when they learn this after years of assuming an academic implementation 
of C++.
</quote>

ref: http://www.baus.net/memory-management

Egads, this blog entry suggests the retval of malloc is not reliable on 
Linux/FreeBSD.

So, how does the anal-retentive programmer deal? 

m

p.s. Did any of you ever see the anal-retentive chef skits on Saturday 
Night Live?  " Now we take the peels from the apple, put them in this 
nice brown bag,  f  o  l   d   the top of the bag down, once ... twice 
... three times, there!  Now, dispose of the bag in the trash. Nice and 
neat!  Ready for the next apple!  ;)


_______________________________________________
kde-pim mailing list
kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic