Re: g_malloc() aborts when enough memory is notfound?




"Emmanuel DELOGET" <logout@free.fr> writes:

> > out of curiosity, how do you popup a dialog if there's no memory
> available?
> 
>     The dialog is created during the init. You also create the label you
> need
>     (so there is no need for a malloc when you have to show the dialog).

Except that GTK+ and GDK and Xlib and even libc all may be doing malloc's
when you popup the dialog. Not to mention the X server.

And then, there is also the problem of reentrancy.

I need to:

 pop up a dialog 
 wait for the user to hit OK
 try again to allocate the memory

>From any conceivable place in the application or GTK+. This is
a decided problem. About the only halfway safe thing I can
think of is to fork off another process and wait for it
to finish.

Basically there are two cases where you run out of memory:

 - You run out of memory by doing a single huge malloc
 - You run out of memory bit by bit.

In the former case, catching the out-of-memory is useful (e.g., the
X server is asked to allocate a 32,000 x 32,000 pixmap due
to signed-unsigned errors.) In the latter case, it probably
isn't.

The user is going to need memory to do anything about the
lack of memory. You can always keep some reserved memory around
which you free when you detect out-of-memory so that you can 
put up a dialog box.

However, in 95% of the cases in which you run out of memory, you are
running out of memory because there is some other process which is
eating memory as fast as it can. So, as soon as you free the reserved
memory, it will get eaten up. 

This is why I don't think trying to be well behaved on
out-of-memory is all that useful. Of course, if it helps
the user to recover even 10% of the time, it may be worth
supporting....

Regards,
                                        Owen



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