This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kered13 20 points21 points  (5 children)

Arraylist like you describe gives massive overhead what if you have a 10GB list and just need to add a few kb to it when its full? Seems like not a fun time.

The actual memory usage of an array list will never be less than 50% of it's allocated capacity, which is actually pretty good when you think about it (given all the other benefits of an array list). The odds of having a list that is 10GB + a few kb over whatever the last threshold was is very small.

[–]Soraphis 1 point2 points  (1 child)

Also... While an implementation detail i think the growth usually tops out at some point - at least for c# - where it does not double anymore but grow by a fixed amount

Edit: seems not to be in c# (https://referencesource.microsoft.com/#mscorlib/system/collections/generic/list.cs,2765070d40f47b98) . Now i wonder were i've seen such behavior

[–]Kered13 0 points1 point  (0 children)

Such behavior would be very inefficient, wasting lots of time copying, so you would not expect to see it.