UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » Variable Declaration!

#26 2006-04-28 11:26 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Variable Declaration!

Memory allocation can fail yes, when the kernel knows that there isn't enough memory at the time you do the malloc. But when allocating tiny pieces of memory it's very unlikely, but still possible.

If "necessary page replacements" is meant to mean swapping, then yes, that will happen when necessary. But there isn't always swap, and it could be full to.

To complicate things further there are things like allocate on demand, overcommit and the OOM killer.

So if you don't mind your program to be killed when all memory is used, then you're lucky and can just quit te program when malloc fails, and avoid doing complicated rescue tumbling.

Offline

#27 2006-04-28 11:48 AM

Lloyd
Member
Registered: 2006-02-13
Posts: 53

Re: Variable Declaration!

"So if you don't mind your program to be killed when all memory is used, then you're lucky and can just quit te program when malloc fails, and avoid doing complicated rescue tumbling."


I am not able to clearly understand this satement. Could you please make it clear?

Offline

#28 2006-04-28 01:37 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Variable Declaration!

I mean that if your program doesn't have to be very reliable under heavy memory pressure, and you don't mind that it can't run under such circumstances, then you can go just the easy way out and exit on allocation failure.

Or in other words, the program won't keep running when there is not enough free memory, but will do something silly like quiting.

Offline

  • Index
  • » C++
  • » Variable Declaration!

Board footer

Powered by FluxBB