RE: [gtk-list] Re: g_malloc() aborts when enough memory is not f




I think you're a bit confused by what Owen meant about mixing calls
to g_malloc()/g_free() and malloc()/free().

What you *can't* do is allocate memory with g_malloc() and free that
allocated memory with free(); neither can you allocate memory with
malloc() and then free that memory with g_free().

You can do basically anything else. Mixing applications that use
malloc/free and g_malloc/g_free on the same system is fine.

You can also use malloc()/free() inside a GTK application as long as
you do so *consistently*

-tony



On 02-Nov-99 Norbert Bladt wrote:
> Owen Taylor wrote:
>> 
>> Mikko Rantalainen <mira@st.jyu.fi> writes:
>> 
>> > While testing exception handling of my program I noticed that
>> > when I'm
>> > using g_malloc() and I'm trying to allocate more memory than
>> > it's
>> > currently available g_malloc calls abort() and thus prevents me
>> > from
>> > handling the problem by myself.
>> >
>> > If I replace g_malloc with plain malloc everything works as
>> > expected.
>> >
>> > How I can tell g_malloc not to abort if memory cannot be
>> > allocated? GLIB
>> > "reference" at http://www.gtk.org/docs/glib_toc.html does not
>> > help much.
>> 
>> If you need non-aborting behavior, use malloc() ;-)
>> 
>> 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.
> If I really do mix it, would my application crash ?
> 
> If yes, will it depend on the system I am using ?
> 
> I have some small command-line utilities which do not use GTK.
> They use malloc and I don't want them to use Glib because
> they are relatively simple and I don't want to force the user
> to install / compile Glib just for these tools.
> 
> However, as soon as I use GTK as the user-interface toolkit and
> use some functions in these command-line utils, my
> problem is, obviously, that I'll use g_malloc (from GTK)
> and malloc (from my utils).
> Will that cause problems ?
> If yes, I'll redefine "malloc" to be "g_malloc" if I compile
> these functions for use in a GTK program. If that is possible,
> that is.
> 
> TIA for any help.
> 
> Norbert.
> 
> -- 
> Norbert Bladt          Payphone Management System Software
Development
> ascom Autelca AG
> Worbstrasse 201                CH-3073 Guemligen, Switzerland
> abladtn@autelca.ascom.ch VOICE: +41 31 999 6552, FAX: +41 31 999
> 6575
> 
> -- 
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
> /dev/null

---
E-Mail: trog@gtk.org
I have the power to HALT PRODUCTION on all TEENAGE SEX COMEDIES!!

Go Bezerk! http://www.gtk.org/~trog



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