gpt4 book ai didi

C-程序: Memory overflow for hash table using array of linked lists

转载 作者:行者123 更新时间:2023-11-30 20:28:13 29 4
gpt4 key购买 nike

系统有 16GB RAM。我们用于存储在哈希表的链表中的节点结构的大小为38字节。这表明哈希表中最多可以存储 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-程序: Memory overflow for hash table using array of linked lists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10416297/

29 4 0