[gt-users] Attach user data to GtGenomeNodes

Sascha Steinbiss steinbiss at zbh.uni-hamburg.de
Thu Feb 19 13:30:46 CET 2009


Gordon Gremme wrote:
>> I could need this functionality right now; what do you think about such
>> an addition to the GtGenomeNode interface?
> 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.

Yes, of course I was talking about giving a *_delete() function pointer 
along with each attached object (like in the cairo example).

> - 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).

This came to me yesterday on my way home, too ;)
Looks like we need some kind of indexing like this after all. Not a 
problem anyway...

> 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?

Sounds about as economical as it could get.
I propose the following interface (e.g. wrapping a hash map):

void gt_genome_node_add_user_data(GtGenomeNode *node,
                                   void *key,
                                   void *data,
                                   GtFree free_func);
void *gt_genome_node_get_user_data(const GtGenomeNode *node,
                                    void *key);
void gt_genome_node_release_user_data(GtGenomeNode *node,
                                       void *key);

Do you think we should introduce a free-function for the key as well, 
like in the generic hashmap class?

> Gordon

Sascha

-- 
Sascha Steinbiss
Center for Bioinformatics
University of Hamburg
Bundesstr. 43
20146 Hamburg
Germany

Email:  steinbiss at zbh.uni-hamburg.de
URL:    http://www.zbh.uni-hamburg.de/steinbiss
Phone:  +49 (40) 42838 7322
FAX:    +49 (40) 42838 7312



More information about the gt-users mailing list