duplicating a GHashTable

Hi i want to create a  GHashTable  from an existing GHashTable
my need is to create a temproery GHashTable for some purpose
i looked here
http://developer.gnome.org/doc/API/2.0/glib/glib-Hash-Tables.html
but i didnt find any easier way

void fff(GHashTable *gp)
{
GHashTable tmpg;
tmpg=make_new _ghashtable(gp);
}
i want to do like this ,is ther any simple way like this or ,i need to access each strings in the existing ghashtable and need to insert into tmp hashtable?
thanks..







 
hiroshAsked:
Who is Participating?
 
stefan73Commented:
Hi hirosh,
There's no direct copy function. You need to use the g_hash_table_foreach() to iterate over the old table to create a copy of it.

Example (haven't tested it):

void copy_hash_table(GHashTable *dest, GHashTable *src){
    g_hash_table_foreach(src,copy_hash_table_iterator,dest);
}

static void copy_hash_table_iterator(gpointer key,gpointer val, gpointer dest){
    g_hash_table_insert((GHashTable*) dest, key,val);
}


(this assumes the dest table is empty when passed)

Cheers!

Stefan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.