glib - c realloc struct - g_hash_table -


I am doing something similar to the following code. I have already gone through the AddtoStructFunction () filling mystruct now, what would I do to do mystruct to mystruct New key (s) has been added without adding every new entry directly to and then adding it to the full g_hash_table in this mystruct .

What would be a good way to do this? Realloc realloc in every new entry?

Zero insertion function (GHashTable * hash, char * str) {g_hash_table_inertert (hash, str, "richmond"); } Zero AddtoStructFunction (struct dastruct ** mystruct) {// g_hash_table_size (g_hash_table) time with all the elements throughout the initially called AddtoStructFunction. Mystruct = (struct dastruct **) malloc (sizeof (struct dastruct *) * g_hash_table_size (g_hash_table)); G_hash_table_iter_init (and iter, g_hash_table); While (g_hash_table_iter_next (& amp; iter, & amp; amp; key_, (gpointer) & amp; val)) {mystruct [i] = (struct dastruct *) malloc (sizeof (struct dastruct)); Mystruct [i] - & gt; MyKey = (gchar *) key_; I ++; }} Zero AddExtraOnes (struct dastruct ** mystruct, four * string) {// realloc mystruct here? // Every time I call AddExtraOnes, then I want to add them [mythruct mystruct [?] - & gt; MyKey = string; } Int i; {InsertFunction (g_hash_table, "RandomStrings") for (i = 0; i & lt; 100000, i ++); } AddtoStructFunction (mystruct); ... // Add this n times Extraones (Maestroct, "Boston");

To re-specify your array, realloc Using the function, the structure will copy this current data of the indicator into the new array if it is successful (if you have 30 to include 30, the first 20 is mystruct examples and < There is an array of arrays for code> realloc that will be similar to your original array.)

Since you are using GLib, you can use GArray B Means you may want to consider a plain mystruct ** . It handles the re-allocation for you.


Comments