Associative arrays in C Associative arrays in C arrays arrays

Associative arrays in C


Glib's hash table. implements a map interface or (associative array).And it's most likely the most used hash table implementation for C.

GHashTable *table=g_hash_table_new(g_str_hash, g_str_equal);/* put */g_hash_table_insert(table,"SOME_KEY","SOME_VALUE");/* get */gchar *value = (gchar *) g_hash_table_lookup(table,"SOME_KEY");


My suspicion is that you would have to write your own. If I understand the architecture you are describing, then you will need to send the entire chunk of data in a single piece. If so, then most libraries will not work for that because they will most likely be allocating multiple pieces of memory, which would require multiple transfers (and an inside understanding of the structure). It would be similar to trying to use a library hash function and then sending its contents over the network on a socket just by passing the root pointer to the send function.

It would be possible to write some utilities of your own that manage a very simple associative array (or hash) in a single block of memory. If the amount of data is small, it could use a simple linear search for the entries and would be a fairly compact bit of code.


Try uthash, a header library implementing a hash table in C. It's small and fairly easy to use.