Re: Possible GHashTable bug?



On Thursday, July 5, 2001, at 05:31  AM, Havoc Pennington wrote:

Derek Simkowiak <dereks realloc net> writes:

	Ooh, ouch; I take this means I also cannot *add* elements while
within g_hash_table_foreach(). That may be a showstopper for me. How can
player1 fire a rocket (resulting in a new entity --the rocket-- for the
hash) if I can't add entities in the iteration of my main loop?  I guess
I'll need a queue or something for post-foreach additions and removals.

	Anyway, thanks for the help.  It would be cool if there were an
Iterator for the GHashTable (g_hash_table_next() or some such) that would
still allow you to add/remove elements between calls.

The usual solution is to flatten the hash into a list, then iterate
over that.

For an example of how to do this, you can look at eel_g_hash_table_safe_for_each. <http://cvs.gnome.org/lxr/ident?i=eel_g_hash_table_safe_for_each>. While I don't like the name I chose that much, I occasionally find it handy to have a version of g_hash_table_foreach that flattens into lists and then uses the lists, allowing the hash table to change during the iteration. It'
s used 3 places in Nautilus.

    -- Darin




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]