系统具有16GB RAM。用于存储在哈希表的链接列表中的节点结构的大小为38bytes。这表明我们可以在哈希表中存储多达4.52亿个节点。但是只有在1300万个节点(大约)之后,才会发生内存溢出。

相关的代码段是这样的:

for (i=0;i<NO_OF_BUCKETS;i++)
  {
    nextptr = hashtable[i];
    while (nextptr != NULL)
      {
        prevptr = nextptr;
        nextptr = nextptr->next;
        free(prevptr);
      }
    hashtable[i] = NULL;
  }

最佳答案

System has 16GB RAM. Our node structure for storing in the linked list of the hash table has a size of 38bytes. This tells that we can store up to 452million nodes in the hash table.


现在,这是一个错误的假设。您是否认为所有RAM都将保留给应用程序中的数据?一点也不。有些操作系统,其他用户级应用程序等也需要内存,您甚至无法确切知道它们需要多少内存。因此,不要期望您可以计算链表实现中的元素数量。

关于c - C-程序:使用链接列表数组的哈希表的内存溢出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10416297/

10-11 17:53