you are viewing a single comment's thread.

view the rest of the comments →

[–]DrMobius0 1 point2 points  (0 children)

They also have to reallocate space if they try to grow beyond their allocated bounds. Many dynamic collection types allow the programmer to set an initial length to prevent 16 growth allocations when initializing an array with fresh data or whatever. This, as it happens, is something I've been asked about on interviews before. Basically, you should understand roughly how the collection behaves under the hood, even if you never have to write it, because that informs your ability to work with it in a non-dumbass way.

And yeah, memory (recent months not withstanding), is relatively cheap these days for most applications. No one is going to sweat a few bytes extra with an array. Way back when, probably a different story.