Re: Proposal: g_set_out_of_mem_handler



Hi David,

> > typedef gboolean  (*GOutOfMemCallback) (void);
> > guint    g_out_of_mem_add_watch (GOutOfMemCallback callback);
> >
> > that makes the callback be called from the main loop, whenever that
> > reserved mem is used. There we can do many things, as long, as we
> > don't use more memory than reserved.
> 
> Beautiful, but may I make a suggestion:
> 
> Can this be made to allow a user to specify an amount of memory
> usage to watch for?

This is done via 
gboolean g_reserved_mem_more
and
void g_reserved_mem_less

so, what you do is:

gboolean
function()
{
  if (!g_reserved_mem_more(what_I_need))
    return FALSE;

  /* now you can use up to what_I_need bytes of mem and they 
   * are garanteed to be available*/

  g_reserved_mem_less(what_I_need)
}


> Then memres could read a config file:
>         MaximumRecommendedMemUsage      2048k
>         MaximumAllowableMemUsage        4096k
> 
> Which would
>         a.  put control of memory in user's hands (when it matters)

It should be in the programmers hand, though. (Ignore me, if that's what you
meant)

>         b.  allow us to deal with the situation at a high-level
>             (not open more windows, etc, on the higher level...)

Can be done with my approach.

>         c.  not introduce too many hacks

Ok, depends on your definition of hack.
 
> I think "memory reservation" is rather poor, b/c then everyone has
> to preallocate there reserve space, which makes memory
> that much more tight. 

Thats true. But one have to pay for everything. If you would check for NULL
after every malloc and handle the error there, the boost in code size would
certainly be worse, than the memory, that my proposal wastes (and of course
the place is just plain wasted)

> Furthermore you trade off waste and safety
> in a manner I find uncomfortable.

Ok, what can I say....
 
Bye,
Sebastian
-- 
Sebastian Wilhelmi                   |            här ovanför alla molnen
mailto:wilhelmi@ira.uka.de           |     är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi   |



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