Re: Possible GHashTable bug?



-> >> 	Ooh, ouch; I take this means I also cannot *add* elements while
-> >> within g_hash_table_foreach(). 

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

	Havoc mentioned that the C++ STL will not allow you to alter a
HashTable while iterating over it.

	I'm not much of a C++ programmer, but I had a friend look that up
in the Microsoft Developer Network docs, and it says that you can, in
fact, alter the STL hash table while iterating over it.

	What it does say is that if you add an element, you cannot be
guaranteed that element will be added before (or after) the
iterator--which makes perfect sense, considering that the hashing
algorithm and the data storage take place within the black box of the
HashTable object.  (Note that for my problem, this would be perfectly
acceptable behaviour, as I could allow an object to execute its update
function before adding it to the hash table.)

	So, I still think it would be cool to have a GHashTable iterator
that would allow insertions and removals (without the overhead of
flattening it into a list first, which is prohibitive for my game loop
that runs at 70 Hz).


--Derek






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