Re: out-of-mem handler



On 14 Feb 2000, Havoc Pennington wrote:

> 
> Sebastian Wilhelmi <wilhelmi@ira.uka.de> writes: 
> > Do not add a callback for out of memory. You wouldn't be allowed to call any
> > glib-function (let alone GTK) inside this handler, as that might screw up the
> > internal state, depending on where the g_malloc call came from, also Xlib
> > doesn't allow overloading the Xmalloc. Thus the callback wouldn't be called,
> > when out of mem in X. 
> > 
> 
> The only reason I want a callback is to do this:
> 
> while (TRUE)
>  {
>    gpointer p;
> 
>    sleep();
>    
>    p = g_malloc_try();
>    if (p)
>      return p;
> }
> 
> (perhaps with a max number of tries for safety)

would this be the callback itself?

if so, i'm not very fond of adding a g_malloc_failed() callback for this
specific purpose (you'd need a similar thing for realloc as well). if that
is really required, i'd rather have a pluggable table of malloc+realloc+free
calls, that programs (ones that *really* need it) could plug into glib
*before* doing any else stuff. (much like libc allowes
"overloading" of its basic allocation functions.)
you are aware, that you need to do similar things at the malloc level
as well then, to prevent it from failing in xlib etc., right?

> I want this specifically for gnome-session. If other apps do this it's
> obviously very bad, but gnome-session should not be the app to fall
> over if memory runs out.

> 
> Havoc
> 

---
ciaoTJ



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