It is true that generic collections perform better than non-generic collections for value types. (i.e. List vs. ArrayList).
But why is that, other than the boxing-unboxing step? Where are the value type objects stored once added to the collection? In non-generic collections, they'll be boxed and stored on heap, what is different in generics?
In generics, such as List<T>
, they're still stored on the heap. The difference is that, internally, a List<int>
makes a single array of integers, and can store the numbers directly. WIth ArrayList, you end up storing an array of references to boxed integer values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With