Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!spool.mu.edu!uunet!ispd-newsserver!sydorow From: sydorow@bisco.kodak.com (Steve Sydorowicz) Newsgroups: comp.windows.x.motif Subject: Re: How to re-manage the same child widget Message-ID: <1991May17.133342.22692@ssd.kodak.com> Date: 17 May 91 13:33:42 GMT Article-I.D.: ssd.1991May17.133342.22692 References: <91May16.183920edt.8838@orasis.vis.toronto.edu> <91May16.230552edt.6244@neat.cs.toronto.edu> Sender: news@ssd.kodak.com Distribution: inet Organization: Eastman Kodak Lines: 61 tjhorton@cs.toronto.edu ("Timothy J. Horton") writes: >tjhorton@vis.toronto.edu ("Timothy J. Horton") writes: >>Most motif widgets are like this; they reallocate copies of whatever you give >>them via pointers. > > (using *either* XtSetValues or convenience routines) > >>Furthermore, if you fetch back resource values via pointers, > > USING CONVENIENCE ROUTINES SUCH AS "XmTextGetString", > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > >>most widgets allocate yet another copy of the resource and pass back the new >>copy, which you normally have to free explicitly. > >XtGetValues normally bypasses this copy/free cycle. For instance, >XmTextGetString gives you a *copy* of the text widget's internal buffer, >wheras XtGetValues on its XmNvalue returns a pointer to the text widget's >internal buffer. > >Thus, getting and setting are different. > > [extras deleted] > >Tim Yes, XtGetValues *normally* bypasses this copy/free cycle. Unfortunately, you picked a bad example with XmNvalue because it has a GetValues hook (from 1.1.1): for (i = 0; i < num_args; i++) { if (!strcmp(args[i].name, XmNvalue)) { *((XtPointer *)args[i].value) = (XtPointer)_XmStringSourceGetValue(GetSrc(widget)); } } and _XmStringSourceGetValue does an XtMalloc eventually. Typically, Motif will have a GetValues hook for all XmString and String typed resources. (*NOT* XmStringTable though. It's probable that you wouldn't want all that copying going on anyway. Though some argue that same point in the XmString and String case, too :-)) The same situation exists in a SetValues hook for these resources. In any event, it was done that way to be *consistent*. In 1.0, and derivatives, it was a hodge-podge of "well, this is copied and this isn't. Hope you have the source so you can go figure out what to do with the memory." All in all, it isn't *so* bad now. It may not be what everyone wants, but it's consistent, which *does* help. Steve -- -------------------------------------------------------------------------------- Stephen J. Sydorowicz Azatar Computer Systems REPLY TO: sydorow@bisco.kodak.com (716)726-5636 Opinions expressed do not reflect those of my employer