A Value That Should Be The Same But It Changes
This part of could should return always the same hash value to each Key isn't it ? But I find that values related to keys they change to each update ...
How can I fix the same value of each key whenever there is an update?
u_int64_t* ReturnValue=NULL;
u_int32_t a;
int sz;
a = nothl(as->addr32[0]);
sz = update(size);
if (ReturnValue=(u_in开发者_如何学运维t64_t*)g_hash_table_lookup(hashtable, (gpointer)&a))
{
g_hash_table_insert(hashtable, (gpointer)&a, (gpointer)ReturnValue);
// I didnt't use g_hash_table_replace() because it will free the key then the value change
}
else g_hash_table_insert(hashtable, (gpointer)&a, (gpointer)&sz)
I don't think you want to insert using a reference to sz
, assuming this is a function call. You should malloc
this instead so that the value doesn't get lost after the function call returns (and then you're pointing to a random memory location that used to be your function's stack). Just make sure you include the code to free this memory, too.
精彩评论