Re: CList memory management with C++ ...



John Schmerge <schmerge cyber com> writes:
When one calls gtk_clist_append(GtkCList * , gchar * text [])

does the clist performs a deep copy of the data in text, or does it just
maintain references to the data in the original array?

It makes a copy - your code should be fine, except the array is
nul-terminated:
 
myClist = gtk_clist_new(1);

for (std::list<std::string>::iterator i = l.begin; i != l.end(); ++i)
{
   char * ptr = i->c_str();  // <- this is the piece that I'm worried about...

   gtk_clist_append(GTK_CLIST(myClist), &ptr);
}


do something like:

char *ptr[2] = { NULL, NULL };
ptr[0] = i->c_str ();

Havoc




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