Re: [gtk-list] potential problems with malloc/free vs. C++ new/delete ???
- From: Havoc Pennington <rhpennin midway uchicago edu>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] potential problems with malloc/free vs. C++ new/delete ???
- Date: Thu, 3 Dec 1998 11:48:14 -0600 (CST)
On Thu, 3 Dec 1998, Dave Reed wrote:
>
> gtk_clist_insert(clist, location, text);
>
> When I clear the clist, I assume the code deallocates the space for
> the strings (correct?)
No, it copies them, which you would know if the function had the right
signature, but Tim is stubbornly wrong about this. ;-)
> Should I instead be using malloc and free (or the glib wrappers) for
> any allocation for gtk even though my program has to use new and
> delete for the C++ class alocations?
>
You should use g_malloc() and g_free() when dealing with memory that goes
in or out of Gtk.
The reason you can't mix malloc/free and new/delete is that new/delete
call constructors and destructors, and (I guess) save extra information so
they know which constructors/destructors to call. If you call delete on
malloc'd memory then the information would not be there. If you call free
on new'd memory then destructors won't be called. Add the awful C++ design
screwup, delete [], and g_free/g_malloc, and you have four ways to free
and three ways to alloc in the same program - you are basically in hell.
Have fun. :-)
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]