Re: Array vs List<>
Michael <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <00cb01c93c25$a4c48990$ee4d9cb0$@net> |
You might find this piece from Eric Lippert worth a read:- http://blogs.msdn.com/ericlippert/archive/2008/09/22/arrays-considered-somew hat-harmful.aspx --Michael -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[email protected]] On Behalf Of Simon Robinson Sent: 01 November 2008 13:01 To: [email protected] Subject: [ADVANCED-DOTNET] Array vs List<> Very minor issue that occurred to me. The project I'm working on seems to have quite a few lists of objects, where each list is read in from a file when the application starts, and is subsequently guaranteed never to change; the data will be accessed constantly but neither the list nor the values of the objects in it will ever be modified. Because I don't know how many elements are going to be in the list until I've read them in, I tend to read them into a List<>, so I can dynamically expand it as I'm reading the elements in. However, because the list is then unchanged, there's no reason for it to be a dynamically expandable list. If it wasn't for the initialization process I'd just store them in a fixed-length array. So I'm curious, what are people's thoughts on keeping the data permanently in a list<>, or discarding the list<> and copying to an array as soon as the data is read in? An array entails the extra copy operation, but may lead to slightly clearer code. I'm guessing for subsequent read access, there's no performance difference. Any other factors I've missed? I realise this is most likely a pretty academic point that would have very little impact on the app either way, but I was curious... =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives No virus found in this incoming message. Checked by AVG. Version: 7.5.549 / Virus Database: 270.8.5/1759 - Release Date: 31/10/2008 16:10 No virus found in this outgoing message. Checked by AVG. Version: 7.5.549 / Virus Database: 270.8.5/1759 - Release Date: 31/10/2008 16:10 =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives