title: Using Memory Allocation with glib's g_new()
body: <p>I have been using g_new() to allocate memory for a single struct which is ok in the following manner.</p>
  
  <pre><code>/*Structure*/
  typedef struct
  {
      guint16 index;
      gchar * date;
      gchar * number;
  }h_item;
  
  /*allocation*/
  h_item * my_h_item = g_new(h_item, 1);
  
  /*freeing function*/
  void free_h_item(h_item * item)
  {
      g_free(item-&gt;date);
      g_free(item-&gt;number);
      g_free(item);
  }
  </code></pre>
  
  <p>I am now trying to do the same for an array[2] of the structs, for example 
  statically allocation is like this, but that would mean it's on the program stack.</p>
  
  <pre><code>h_item my_h_item[5];
  </code></pre>
  
  <p>I would like to dynamically allocate the same above, but I seem to have trouble when running the program...</p>
  
  <pre><code>/*Structure*/
  typedef struct
  {
      guint16 index;
      gchar * date;
      gchar * number;
  }h_item;
  
  
  /*freeing function*/
  void free_h_item(h_item * item)
  {
      g_free(item-&gt;date);
      g_free(item-&gt;number);
      g_free(item);
  }
  
  static h_item * my_h_item[2];
  
  int main()
  {
      /*allocation*/
      my_h_item[2] = g_new(h_item, 2);
  
      my_h_item[0]-&gt;date = g_strdup("12345"); /*Test*/
      return 0;
  }
  </code></pre>
  
  <p>This program compiles but segfaults...</p>
  
  <pre><code>#0  0x00000000004007a7 in main () at struct_memory.c:30
  30      my_h_item[0]-&gt;date = g_strdup("12345"); /*Test*/
  </code></pre>
  
  <p>Where is my allocation going wrong?</p>