Re: [gtk-list] Re: g_malloc() aborts when enough memory is not found?
- From: "Emmanuel DELOGET" <logout free fr>
- To: <gtk-list redhat com>
- Subject: Re: [gtk-list] Re: g_malloc() aborts when enough memory is not found?
- Date: Tue, 2 Nov 1999 19:55:31 +0100
> Mikko Rantalainen <mira@st.jyu.fi> writes:
> [snipped - sorry]
>
> If you need non-aborting behavior, use malloc() ;-)
Hi Owen,
I don't know if this is a good idea. If it is possible
to extend the callback architecture to glib (for version
1.30, perhaps :)), the abort behavior should be avoided in
some cases. Consider the following (in a multiple window
text processor)
enum
{
GALLOC_WAIT, /* do not malloc, return NULL on g_malloc()
error */
GALLOC_NOWAIT, /* try to alloc again */
GALLOC_ERROR /* cannot do anything, so g_malloc() aborts */
};
/* during init */
guint granularity = 64 * 1024 ; /* ask for 64ko on a malloc error */
gallocator_init(my_callback_for_the_no_more_memory_error, granularity);
/* lots of g_malloc and then...*/
gint my_callback_..._error(guint requested_size)
{
if (number_of_opened_docs > 1)
{
show_simple_dialog("no more memory : you should close some
documents");
return (GALLOC_WAIT);
}
else
{
show_simple_dialog("fatal : no more memory");
return (GALLOC_ERROR);
}
}
Does not seems to be bad for me :)
Emmanuel
>
> g_malloc() is basically a wrapper around malloc() that aborts
> if memory cannot be allocated.
>
> [ Right now, there is also the ability to add some simple checking
> into the g_malloc() with compile time options to g_malloc() -
> so you should not mix malloc() and g_free() or vice-versa.
>
> Use of these features is discouraged and they will most likely
> be removed in the feature. ]
>
> Regards,
> Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]