gtk新手 哈希表 求助
下面 代码 有什么问题? 一调用 taphash_write 就出错
static GHashTable * applink_hash_tapinf = NULL;
guint32 g_line_num =0 ;
void taphash_init(void)
{
applink_hash_tapinf = g_hash_table_new(g_int_hash,g_int_equal);
}
void taphash_insert(guint32 frame_num, guint32 line_num)
{
g_hash_table_insert(applink_hash_tapinf, (gpointer)(frame_num), (gpointer)(line_num));
}
static gpointer *taphash_lookup( guint32 frame_num )
{
return g_hash_table_lookup(applink_hash_tapinf, (gpointer)(frame_num));
}
void taphash_cleanup(void)
{
g_hash_table_destroy(applink_hash_tapinf);
applink_hash_tapinf = NULL;
g_line_num =0 ;
}
void taphash_write(guint32* buf, guint32 bufsize, guint32 fd_num )
{
if(taphash_lookup(fd_num) == NULL)
{
taphash_insert(fd_num, g_line_num);
g_line_num++;
...
}
else
{
int line_num = (int)taphash_lookup(fd_num);
...
}
}
哈希?gtk
[解决办法]
#include <glib.h>
int main(int arg, char **argv)
{
GHashTable* hash = g_hash_table_new(g_int_hash, g_int_equal);
gint* key = g_new(gint, 1);
gint value = 5;
*key = 1;
g_hash_table_insert(hash, key, (gpointer)value);
return 0;
}