[gt-users] Attach user data to GtGenomeNodes
Gordon Gremme
gremme at gmail.com
Thu Feb 19 11:41:09 CET 2009
> it would be nice if there was a possibility to attach (a pointer to)
> arbitrary user data to a GtGenomeNode object. This could be used to pass
> information for which there is no designated property from one stream to
> another. A similar technique is used in the cairo framework
> (http://cairographics.org/manual/cairo-surface.html#cairo-surface-set-user-data)
> in which there are cairo_surface_set_user_data() and
> cairo_surface_get_user_data() methods for exactly that purpose. (I do
> not think we would need their key functionality, just a simple void
> pointer would be enough).
>
> I could need this functionality right now; what do you think about such
> an addition to the GtGenomeNode interface?
Sounds like a good idea to me!
But I think we need a full-fledged implementation similar to the one
in Cairo (including destructors and keys) for the following reasons:
- memleaks: without a destructor it seems to be impossible to avoid
memleaks. If a stream (which doesn't use the user data at all)
produces an error and currently owns nodes with user data attached, it
will leak the user data when freeing the nodes. If the node has the
destructor for the user data, it can take of the freeing itself.
- composability: Lets say you have stream A which adds user data and
stream A' which removes it (and a similar pair B and B'). If you want
to compose the four (or at least three of them), you would run into
all sorts of problems (without keys).
Since the memory consumption of GenomeNodes is very critical, I would
add a single pointer to it. The pointer then holds the ``dictionary''
(whatever is used) on demand. I.e., the object to store the user data
objects would be created when the first user data is added and removed
when the last user data is removed.
What do you think?
Gordon
More information about the gt-users
mailing list