which one is more memory efficient?
which one works faster with 1000000 items?
is there anything better?
which one is more memory efficient? which one works faster with 1000000 items? is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
List<T>is generally preferable to using anArrayListbecause it is a type safe collection. This means that you get build time type safety. It is also more memory efficient for value types because entries in anArrayListwill be boxed because its a list of type object:eg: Adding an integer to a
List<int>will put the data on the heap using anint[]as the underlying data structure. Adding an integer to anArrayListwill put the data on the heap, but because the underlying data structure is anobject[], the data has to be boxed which means a pointer also has to be stored on the heap which requires more memory to be allocated.The memory allocation for an
ArrayListand aList<T> : class(a list of reference types) is exactly the same.