1

I am trying to make a server that are going to handle alot of connections and therefore need great performance. But I can't really decide if I should use a List or a ArrayList for sockets. I've read somewhere here on stackoverflow that List should be used instead of a ArrayList because ArrayList is kind of outdated. But also I see alot of articles and other people using ArrayList for listing their sockets. So is there any kind soul out there that maybe could answer me what is best for performance?

techbech
  • 3,754
  • 5
  • 20
  • 28
  • Duplicate of http://stackoverflow.com/questions/10815565/which-is-better-array-arraylist-or-listt-in-terms-of-performance-and-speed ? – Brian Green Sep 20 '13 at 17:22
  • ArrayList isn't generic. Are you really interested in casting every element for the slight difference in speed? Not to mention the errors that might easily slip trough. – Jeroen Vannevel Sep 20 '13 at 17:23
  • How do you know that you need that micro optimizations. Have you profiled your code and seen where is the bottleneck? – I4V Sep 20 '13 at 17:23
  • 2
    Use `List` for the sole purpose that it's generic. **If and only if** you run into performance issues, then look into alternative options. For now it's a moot point. – Dave Zych Sep 20 '13 at 17:25

3 Answers3

6

All collections - lists, array lists, linked lists, and so on, - stay in memory. You are writing a program that manages socket I/O, so in terms of performance it does not really matter what collection you use: the performance of that portion of your system will be dominated by I/O and system calls to manage sockets.

That is why I would stay with List<T>, the "more modern" option (strictly speaking, List<T> is more than ten years old, so it is "modern" only in comparison to the ArrayList).

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
2

I don't think you will be able to meassure the preformance between an ArrayList and a List<T> in combination with socket handling. In my opinion,

I would use a List<T> be cause it is generic. You don't have to program extra castings and the code will be more readable.

Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57
1

Depends on how you're going to use it. Check this out and decide from there

ArrayList vs List

Community
  • 1
  • 1
VortexMath396
  • 66
  • 1
  • 4