Re: Memory allocation troubles



On Tue, 19 Oct 2004 09:27:22 +0200
Olaf Fr±czyk <olaf cbk poznan pl> wrote:
I write an application that requires much memory to run.
It is impossible to assume that every time I ask for memory I'll get
it. Aborting program is not an option, because before dying I need to
clean things up.

If you're running this program on Linux, you have a bit of a problem. 
When a process asks the Linux kernel for more memory, the kernel
increases size of the process' data segment, but does not actually
assign physical memory (ram or swap) until the program tries to access
it.  So while the initial call to malloc (and therefore g_new) may
succeed, your program may still be suddenly terminated if the system
runs out of memory.

From the linux malloc(3) manpage:
  "Linux follows an optimistic memory allocation strategy.  This means
  that when malloc() returns non-NULL there is no guarantee that the
  memory really is available.  In case it turns  out  that  the system
  is out of memory, one or more processes will be killed by the infamous
  OOM killer."

JV



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]