Re: glib CVS ?



On Sun, 25 Nov 2001 23:09:29 +0100 (CET)
Tim Janik <timj gtk org> wrote:

> > > you could plug your own memory allocation routines into the glib memory
> > > system (it has hooks that allow you to do so without patching). It will
> > > be non-trivial however to gracefully recover from a failed memory 
> > > allocation. Glib-2.0 has g_try_malloc() that you can use in your own
> > > routines wherever it makes sense.
> > 
> > GString should be changed in order to use these
> > g_try_realloc/g_try_malloc in order to recover from failed memory
> > allocation, don't you think so ?
> 
> nope, GString's API doesn't have any provisions for reporting errors
> ala "don't use me i couldn't allocate enough memory".

Couldn't it be added (I can do it and submit a patch)

> a good example of where g_try_malloc() is apropriate is the pixbuf
> loading code, where out-of-mem is just another error condition
> besides various other reasons for why an image couldn't get loaded,
> and the allocation failing my very well be due to a broken image
> file (say it told you to allocater space for 65535*65535 pixels).

The fact is that I am developing a library where I use
GStrings and I can't exit the main program in case the memory
allocation could not be done, and GString I will be manipulating
can be enough large to induce out-of-memory errors.
The program that will use this library should not exit on
failure.

I really think that a library should not make a decision for
the program that uses it do fail and to exit.

-- 
   ~       Speed Metal MUA p4tch3rZ
  'v'
 // \\                  DINH V. Hoà
/(   )\
 ^`~'^ 



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