janet@123 0 Newbie Poster

I am trying to use the glib HashTable implementation for my code and facing some issues in memory allocations. The code I've written is:

GHashTable *g_hash_table; 
  g_hash_table = g_hash_table_new (g_direct_hash, g_direct_equal);

  gint *port, *src_value, *value;
  guint32 *dst_key, *key;

   while(1) {
      key = g_malloc (sizeof *key);
      dst_key = g_malloc (sizeof *dst_key);
      port = g_malloc (sizeof *port);

      *port = ntohs (pkt_in->in_port);

      *key = ip_src;
      *dst_key = ip_dst;

      src_value = g_hash_table_lookup (g_hash_table, key);

      if (src_value == NULL)
    {       /// store new record
      g_hash_table_insert (g_hash_table, key, port);


    else {
//      printf("found the src value = %d\n", *src_value);

      ///-----Learning OutPort---

      value = g_hash_table_lookup (g_hash_table, dst_key);

      if (value == NULL)
     // do something

      out_port = *value;


Now when I run the code I get errors like:

MEMORY-ERROR: [7219]: GSlice: assertion failed: sys_page_size == 0 Segmentation fault


(process:23935): GLib-ERROR (recursed) **: /build/buildd/glib2.0-2.28.6/./glib/gmem.c:202: failed to allocate 1073741816 bytes

I am not sure how to resolve this issue and what is the proper way of allocating memory in glib and I need some help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.