Re: Proposal: g_set_out_of_mem_handler



> So, what did I do then:
>  
> I simply added a new lib to GLib (which is something like gthread and
> gmodule): gmemres (g memory reservation).
> 
> It contains a (actually only slightly) hacked version of Doug Lea's malloc, as
> found in glibc[1]. This simply makes sure, that between the last allocation
> and the real end of the heap, as allocated from the OS with sbrk, there will
> always be g_reserved_mem_size (set it with g_reserved_mem_set, which will
> return TRUE, if the reservation succeded) bytes left. If that wasn't possible,
> then the function 
> g_reserved_mem_used will return TRUE. Then I provide the function 
> 
> 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?

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)
	b.  allow us to deal with the situation at a high-level
	    (not open more windows, etc, on the higher level...)
	c.  not introduce too many hacks

I think "memory reservation" is rather poor, b/c then everyone has
to preallocate there reserve space, which makes memory
that much more tight.  Furthermore you trade off waste and safety
in a manner I find uncomfortable.

- Dave



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