Possble problem with g_hash_table_remove() not resizing table
- From: darren seattleserver com
- To: gtk-devel-list gnome org
- Subject: Possble problem with g_hash_table_remove() not resizing table
- Date: Wed, 31 May 2000 21:13:20 GMT
Hi,
I'm having a problem where a GHashTable doesn't always get resized
after removing an element. For example if the table size is 100, and
I remove one record, the table size is still 100 rather than 99.
This only seems to happen when the table values and keys are dynamically
allocated, if the data are static it seems to work fine. I've run this
on a couple of RedHat 6.2 systems and they behave the same. What's really
odd is that the problem doesn't seem to happen on HP-UX 10.20, just the
Linux. This is with glib-1.2.6. Here is the test code I am using:
#include <glib.h>
#define CYCLES 100000
int main(int argc, char **argv)
{
GHashTable *table;
int *key;
int *val;
int i;
gpointer ori_key;
gpointer ori_val;
int lkey;
table = g_hash_table_new(g_int_hash, g_int_equal);
for(i=0;i<CYCLES;i++)
{
key = g_new0(int, 1);
val = g_new0(int, 1);
*key = i;
*val = i+2 * 4;
g_hash_table_insert(table, (gpointer)key, (gpointer)val);
}
g_print("Table has %d records\n", g_hash_table_size(table));
for(i=0;i<CYCLES;i++)
{
lkey = i;
if(!g_hash_table_lookup_extended(table, (gpointer)&lkey, &ori_key,
&ori_val))
{
g_warning("failed to find value for key %d\n", i);
continue;
}
g_free(ori_key);
g_free(ori_val);
g_hash_table_remove(table, (gpointer)&lkey);
}
g_print("Table now has %d records\n", g_hash_table_size(table));
return(0);
}
I would expect the table size to be zero at the end, instead it is 1208.
Is something wrong or am I doing this wrong?
Thanks,
Darren McClelland
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]