[10641] in The GTK GIMP ToolKit mailing list archive

home help back first fref pref prev next nref lref last post

[gtk-list] potential problems with malloc/free vs. C++ new/delete ???

daemon@ATHENA.MIT.EDU (Dave Reed)
Thu Dec 3 09:02:17 1998

Date: Thu, 3 Dec 1998 09:05:53 -0500
From: Dave Reed <dreed@capital.edu>
To: gtk-list@redhat.com
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com


I know many of you are also writing C++ code using gtk so hopefully
you can answer my question.  I remember reading somewhere that it's a
"bad idea" to mix malloc/free with new/delete (if you allocate with
new, you need to deallocate with delete and if you allocate with
malloc you need to deallocate with free).  I've got some code where I
allocate with new the strings for a clist like below:

  gchar **text;

  text = new gchar*[8];
  for (i=0; i<8; i++) {
    text[i] = new char[100];
  }

	// set values of text[i]
  
  gtk_clist_insert(clist, location, text);

When I clear the clist, I assume the code deallocates the space for
the strings (correct?) and that it also would use free (obviously
since it's C code).  So far my program appears to works fine, but is
this going to cause a memory problem that is going to haunt me later?

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?

Thanks,
Dave
dreed@capital.edu

-- 
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


home help back first fref pref prev next nref lref last post