且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

T>名单℃之间的差异;和LinkedList< T>

更新时间:2022-01-10 15:56:56

好了,列表&LT; T&GT; 基本上是由一个数组,通常比更大的支持目前的一些项目。元素被置于一个阵列,并且当旧用完空间中创建一个新的数组。这是快速通过索引访问,但在缓慢取出或插入列表中或在开始元素。 。添加/在列表的末尾删除条目是相当便宜。

Well, List<T> is basically backed by an array which is usually bigger than the current number of items. The elements are put in an array, and a new array is created when the old one runs out of space. This is fast for access by index, but slow at removing or inserting elements within the list or at the start. Adding/removing entries at the end of the list is reasonably cheap.

的LinkedList&LT; T&GT; 是一个doubly-链表 - 每个节点都知道它以前的条目及其下一个。这是快后插入/特定节点(或头/尾)之前,但慢于通过索引访问

LinkedList<T> is a doubly-linked list - each node knows its previous entry and its next one. This is fast for inserting after/before a particular node (or the head/tail), but slow at access by index.

的LinkedList&LT; T&GT ; 一般的时间比更多的内存列表&LT; T&GT; ,因为它需要所有的下一首/上引用空间 - 并且数据将可能有参考较少局部性,因为每个节点都是一个单独的对象。在另一方面,列表&LT; T&GT; 可以的有一个支持数组比其当前需要更大

LinkedList<T> will usually take more memory than List<T> because it needs space for all those next/previous references - and the data will probably have less locality of reference, as each node is a separate object. On the other hand, a List<T> can have a backing array which is much larger than its current needs.