Hello

I am trying to allocate a bucket of hashes in advance and then use pointers from these hashes as and when needed.

let me explain

I have a mainHash which i make like so
mainHash = g_hash_table_new(g_str_hash, g_str_equal);
Where the key is a string and the value is a pointer to another Hash.

Now everytime I get a record, i do a lookup in the mainHash and if it is found then I go to the Hash pointed to by the value and then insert the record into that Hash. If not found I create a new hash and then insert this into the mainHash and then the record into this newly created hash.

What i wish to do is however, create the mainHash such that it contains lets say 5000 pointers to unused Hashes. Now whenever i get a record, i wish to do a lookup on the mainHash and if not found then use one of those pointers from the mainHash and decrement the number of available pointers by 1. Ie allocate memory to a bucket of hashes and then use that bucket whenever i need.

Right now this is what i am doing :
Code:
mainHash = g_hash_table_new(g_str_hash, g_str_equal);
.....
....
..
<GOT NEW RECORD>
GHashTable *recHash;
if ((recHash =(GHashTable*) g_hash_table_lookup(mainHash, key)) == NULL)
{
// Look for an entry in the mainHash for this symbolUserId ,
// if not found then create a new hash with key=symbolUserId, value = pointer to new hash
// Insert this symbolUserId into the mainHash

//Memory mgmt - take a memory from previously allocated mem

//Create new hash
recHash = g_hash_table_new(g_str_hash, g_str_equal);

//Insert into mainHash
g_hash_table_insert(mainHash, g_strdup(key), (gpointer)recHash);

//Insert record into new hash
g_hash_table_insert(recHash,strdup(refKey),g_strdu p(refKeys));
}
else
{
// if an entry is found in the mainHash, then use the value of the found
// key(symbolUserId) and insert this object into that hash

//Insert record into found hash
g_hash_table_insert(recHash, g_strdup(refKey), g_strdup(refKeys));

}
Can someone tell me how to allocate the bucket and then use hashes from that bucket.

thanks.