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

Re: Out of memory conditions and g_malloc



On Wed, 2003-09-24 at 12:36, Philippe Laporte wrote:
> Hi,
>     The documentation at
> http://www.gtk.org/tutorial/sec-memorymanagement.html
> has:
> 
> "gpointer g_malloc( gulong size );
> 
> This is a replacement for malloc(). You do not need to check the return 
> value as it is done for you in this function. If the memory allocation 
> fails for whatever reasons, your applications will be terminated.
> "
> 
> Is there a way to specify a handler for when memory allocation fails, so 
> that we may have the opportunity to get something more graceful than a 
> terminated application?

g_mem_set_vtable():

http://developer.gnome.org/doc/API/2.0/glib/glib-Memory-Allocation.html#g-mem-set-vtable

allows you to replace the backend function that g_malloc() uses; with
the caveat that:
 
 - The function still needs to return the requested memory - if it
   returns NULL, g_malloc() will abort.

 - The function cannot call any GLib or GTK+ functions, because of
   reentrancy concerns.

So, the function is restricted to doing things like a) wait, b) free up
a "parachute" block of memory c) free up application specific caches 
d) communciate with another process to put up notification to the user.

Regards,
						Owen





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