[comp.windows.x] More questions about resource ownership

jason@tfs.COM (Jason P. Venner) (05/21/91)

Let's say I have a widget that uses a pixmap, and when it is
destroyed, it delete's it's pixmap.  Is there a way for me to get an
additional handle on it, so that it is not truely destroyed by the
XFreePixmap call?

Jason

swick@athena.mit.EDU (Ralph Swick) (05/21/91)

    Let's say I have a widget that uses a pixmap, and when it is
    destroyed, it delete's it's pixmap.  Is there a way for me to get an
    additional handle on it, so that it is not truely destroyed by the
    XFreePixmap call?

There is no direct way to tell the server to map a second (pixmap) resource
id onto the same instance of the pixmap.

If the widget were to get its pixmap through a resource type converter
(say, for example, StringToPixmap) then you could use resource reference
counting (see XtCacheRefCount).  In fact, you would be forced to do so
if you actually wanted the pixmap to be freed (by a resource destructor;
see XtDestructor) when all references have been deleted.

An additional benefit of using a resource type converter is that any
other object instance with the same resource value specification can
automatically get the same pixmap if desired.

Reference counting is implemented only in the Xt calls that could actually
invoke a converter.  So, to get another reference to the same object you
need to create another widget, use XtGetApplicationResources, or use
XtGetSubresources.  In particular; calling XtGetValues does not change
the reference count.