[comp.windows.x] Xt Resource Cache Counting

doyle@doyled.b23b.ingr (Doyle C. Davidson) (06/28/91)

Regarding resource cache counting:

Say I have a widget of class fooClass with an XtNforeground resource.

Suppose I want to change the foreground color (let's say I want to
blink the widget) so I get an alternate color via:

    XtConvertAndStore(w, XtRString, &src, XtRPixel, &dest);

Xt adds a XtNdestroyCallback to the widget to decrement the
resource's reference count and free the cached resource if zero.
Right?

To use the same color for a second widget, I must then call
XtConvertAndStore again if I want to properly maintain the
resource cache count.  Correct?

Because, if I don't, and I destroy the first widget (the one
used in the XtConvertAndStore) my reference count could
possible reach zero even though the second widget still
may use that secondary pixel value.

Doyle 
    "I fear explanations explanatory of things explained." -- unknown
------------------------------------------------------------------
Doyle C. Davidson              |
Intergraph Corp.               |  These comments are...
   Everywhere You Look!!       |
Third Party Software           |
   Product Development         |     \\  /
(205) 730-2000                 |      \\/
                               |      /\\  clusively my own.
..!b23b!doyled!doyle  -or-     |     /  \\
    ...ingr.com!doyle          |
------------------------------------------------------------------

swick@crl.dec.com (Ralph Swick) (06/28/91)

> Xt adds a XtNdestroyCallback to the widget to decrement the
> resource's reference count and free the cached resource if zero.
> Right?

Right, in general.  If the resource happens to already exist (i.e.
this is not the first reference) and if a previous reference was
marked as initialResourcesPersistent:True, then no reference counting
is done and no callback is added.  InitialResourcesPersistent is
described with XtConvertAndStore (page 800 of the Digital Press book)
but it must actually be specified when objects are created; i.e.
with XtCreateWidget.

> To use the same color for a second widget, I must then call
> XtConvertAndStore again if I want to properly maintain the
> resource cache count.  Correct?

Correct.