是否可以将 GArray 用作 GHashTable 中的值?

Is it possible to use a GArray as a value in a GHashTable?

我正在尝试将字符串映射到 GArrays using a GHashTable。到目前为止,我还没有成功。

我这样声明哈希表:

hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);

我的 GArray 是这样的:

array = g_array_new(1, 1, sizeof(uint64_t));

我正在尝试将数组插入到哈希表中。插入后,我检查它是否在那里。密钥似乎在那里,但它的散列值是 NULL.

GArray *old_array;

g_hash_table_insert(hash_table,
           (gpointer) g_strdup(path),
           (gpointer) array);

if (g_hash_table_lookup_extended(hash_table,
            path, NULL, (void **) old_array)) {
    printf("stored value is %p\n", old_array);
}

我想做的事情可行吗?如果是这样,如何避免 NULL 值?

菜鸟错误。需要传入&old_array.

GArray *old_array;

g_hash_table_insert(hash_table,
           (gpointer) g_strdup(path),
           (gpointer) array);

if (g_hash_table_lookup_extended(hash_table,
            path, NULL, (void **) &old_array)) {
    printf("stored value is %p\n", old_array);
}