Scott Hanselman
Posts: 1031
Nickname: glucopilot
Registered: Aug, 2003
|
Scott Hanselman is the Chief Architect at Corillian Corporation and the Microsoft RD for Oregon.
|
|
|
|
Wesner's thoughts on Collection versus List
|
Posted: Aug 2, 2004 1:59 PM
|
|
|
This post originated from an RSS feed registered with .NET Buzz
by Scott Hanselman.
|
Original Post: Wesner's thoughts on Collection versus List
Feed Title: Scott Hanselman's ComputerZen.com
Feed URL: http://radio-weblogs.com/0106747/rss.xml
Feed Description: Scott Hanselman's ComputerZen.com is a .NET/WebServices/XML Weblog. I offer details of obscurities (internals of ASP.NET, WebServices, XML, etc) and best practices from real world scenarios.
|
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Scott Hanselman
Latest Posts From Scott Hanselman's ComputerZen.com
|
|
Wesner
offers his thoughts on my question, What's
the difference between System.Collections.Generic.Collection and System.Collections.Generic.List?
I think there are two possible reasons.
-
Collection<T> appears to be a replacement for CollectionBase, which provided
virtual methods to detect insertions, deletions and changes.
-
The new List class no longer provides any virtual methods as did the original
ArrayList for performance reasons..
[Wesner
Moise]
He also educates us on some of the differences between List<T> and the 2.0 ArrayList.
-
List<T> does not use any virtual methods. As a result, a number of methods
such as the list indexer methods can now be inlined.
-
With the default constructor, List<T> and Whidbey ArrayList do not allocate
any memory for its items, so an empty list represents a very compact object--comparable
in size to an empty array. (8 bytes for Array, 12 bytes for List, 16 bytes for Whidbey
ArrayList) It uses the empty array trick that I wrote about in an earlier post. In
contrast, earlier versions of ArrayList would allocate space for 16 items by default.
-
The initial buffer size when an item is actually added is 4 items not 16 as before.
-
List<T> returns an struct-based enumerator, so that iterating through foreach
now involves no memory allocations at all.
[Wesner
Moise]
Read: Wesner's thoughts on Collection versus List
|
|