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

Who is Participating?
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){

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)


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.