链表的最大限制
Maximum limit of Linkedlist
我是 CS 的新手 world.While 阅读了一些书籍,我检查了内存的动态分配,在程序运行时动态分配内存并且内存被称为 heap.So 这意味着每当我想创建一个链表中的新节点存储在堆上?否则它会存储在内存中并在运行时访问?
而且我还检查了每当任何程序 运行 时,OS 都会为其创建 PCB,包括至少 4 个以下部分:
- 堆段
- 堆栈段
- 数据段
- 代码段
并且堆段和堆栈段动态增长取决于代码(向上或向下取决于系统)。
所以我的基本问题是
The maximum element we can add in Linkedlist until system memory exhausts or heap memory exhausts?
我读到它直到系统内存 exhausts.But 我想知道如何?
如果动态分配内存,则可以从堆中获取。
从上面的陈述可以直接得出结论,如果动态分配列表的节点,最大节点数受堆大小限制,即受堆内存量限制。
我读过的最佳解释:
Because the heap grows up and the stack grows down, they basically limit each other. Also, because both type of segments are writeable, it wasn't always a violation for one of them to cross the boundary, so you could have buffer or stack overflow. Now there are mechanism to stop them from happening.
There is a set limit for heap (stack) for each process to start with. This limit can be changed at runtime (using brk()/sbrk()). Basically what happens is when the process needs more heap space and it has run out of allocated space, the standard library will issue the call to the OS. The OS will allocate a page, which usually will be manage by user library for the program to use. I.e. if the program wants 1 KiB, the OS will give additional 4 KiB and the library will give 1 KiB to the program and have 3 KiB left for use when the program ask for more next time.
摘自here。
我是 CS 的新手 world.While 阅读了一些书籍,我检查了内存的动态分配,在程序运行时动态分配内存并且内存被称为 heap.So 这意味着每当我想创建一个链表中的新节点存储在堆上?否则它会存储在内存中并在运行时访问?
而且我还检查了每当任何程序 运行 时,OS 都会为其创建 PCB,包括至少 4 个以下部分:
- 堆段
- 堆栈段
- 数据段
- 代码段
并且堆段和堆栈段动态增长取决于代码(向上或向下取决于系统)。
所以我的基本问题是
The maximum element we can add in Linkedlist until system memory exhausts or heap memory exhausts?
我读到它直到系统内存 exhausts.But 我想知道如何?
如果动态分配内存,则可以从堆中获取。
从上面的陈述可以直接得出结论,如果动态分配列表的节点,最大节点数受堆大小限制,即受堆内存量限制。
我读过的最佳解释:
Because the heap grows up and the stack grows down, they basically limit each other. Also, because both type of segments are writeable, it wasn't always a violation for one of them to cross the boundary, so you could have buffer or stack overflow. Now there are mechanism to stop them from happening.
There is a set limit for heap (stack) for each process to start with. This limit can be changed at runtime (using brk()/sbrk()). Basically what happens is when the process needs more heap space and it has run out of allocated space, the standard library will issue the call to the OS. The OS will allocate a page, which usually will be manage by user library for the program to use. I.e. if the program wants 1 KiB, the OS will give additional 4 KiB and the library will give 1 KiB to the program and have 3 KiB left for use when the program ask for more next time.
摘自here。